0

アクティビティの 1 つが stack.back ボタンで正しく機能しない理由を突き止めようとしています。

ユーザーが Main アクティビティで画像ボタンを押すと、Activity Brain が起動します。これは正常に機能し、戻るボタンは Brain から期待どおりに動作します (つまり、期待どおりにメイン アクティビティに戻ります)。

脳内で、ユーザーが押した画像ボタンに基づいて PDF を起動したいのですが、以下のコードを使用して URI を介してこれを実行しています。PDF は正常に読み込まれますが、アクロバット内で戻ると、アプリは脳ではなくメイン アクティビティに戻ります。これは私が望む(または期待する)動作ではありません。私はアプリ開発者ガイドを読み、Intent Flag_activity ですべてのオプションを試しましたが (私はそう思います)、戻るボタンの動作を修正できませんでした。別のPDFにリンクしようとしましたが(アクロバットでランダムなものだった場合)、アプリは同じように動作し、常にメインに戻り、必要な頭脳には戻りません。

私は Imagebuttons を使用して、ユーザーが pdf を選択できるようにしています。以下のコードは、pdf を表示するための URI / インテントを呼び出しています。私が試した Intent.Flags のうち 2 つを残しましたが、増幅のために運がありませんでした。Intent.Flag_Activity_Clear_Top が機能することを期待していましたが、何かを見逃したに違いありません。

脳の活動は、次の onClick コードを使用して main から呼び出されます

 if (v==bbrain) {
                    Intent startbrain = new Intent(Main.this, Brain.class); //this is the Brain chooser
                    startActivity(startbrain);
                overridePendingTransition(R.anim.pull_from_left_enter, R.anim.pull_out_to_left_exit);
                    }

すると、脳活動 java は次のようになります。

public void onClick(View v) {

            if (v==bhome); {
            Intent starthome = new Intent(Brain.this, Main.class); //this is main screen
            startActivity(starthome);
            overridePendingTransition(R.anim.zoom_enter, R.anim.zoom_exit);
            }

            if (v==babouttest){
                Intent start1gp = new Intent(Brain.this, AboutScreen.class); //this is 1gp lesson
                startActivity(start1gp);
                overridePendingTransition(R.anim.pull_from_left_enter, R.anim.pull_out_to_left_exit);
            }

            if (v==imagepetro) {
                File file = new File("/sdcard/documents/1.pdf");
                  if (file.exists()) {
                        Uri path = Uri.fromFile(file);
                        Intent intent = new Intent(Intent.ACTION_VIEW);
                        intent.setDataAndType(path, "application/pdf");
                        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

                        try {
                            startActivity(intent);
                            overridePendingTransition(R.anim.zoom_enter, R.anim.zoom_exit);
                        } 
                        catch (ActivityNotFoundException e) {

                        }
                  }
            }   //end of load

 if (v==imagesteam) {
                File file = new File("/sdcard/documents/2.pdf");
                  if (file.exists()) {
                        Uri path = Uri.fromFile(file);
                        Intent intent = new Intent(Intent.ACTION_VIEW);
                        intent.setDataAndType(path, "application/pdf");
                        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

                        try {
                            startActivity(intent);
                            overridePendingTransition(R.anim.zoom_enter, R.anim.zoom_exit);
                        } 
                        catch (ActivityNotFoundException e) {

                        }
                  }
            }   //end of load

   }

  //menu inflator bits
          @Override
            public boolean onCreateOptionsMenu(Menu menu) {
                getMenuInflater().inflate(R.menu.activity_brain, menu);
                return true;
            }  

            @Override
            public boolean onOptionsItemSelected(MenuItem item) {
                switch (item.getItemId()) {
                    case android.R.id.home:
                        NavUtils.navigateUpFromSameTask(this);
                        return true;
                }
                return super.onOptionsItemSelected(item);
            }

}

このアプリを書いているときに、他の場所で何かを見逃していないかどうかわかりませんか? 以下は、マニフェストからの脳と主な活動セクションです。違いがある場合

   <activity
        android:name=".Main"
        android:label="@string/title_activity_main"
        android:screenOrientation="landscape" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <!-- <category android:name="android.intent.category.LAUNCHER" /> -->
        </intent-filter>
    </activity>
 <activity
        android:name=".Brain"
        android:label="@string/title_activity_brain"
        android:screenOrientation="landscape" >
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value="com.trainer.Main" />
    </activity>

このコードが機能しない理由がまったくわかりません。他のアクティビティで他の場所から PDF を起動していますが、URI の方法はうまく機能しています。

十分な詳細を提供できれば幸いです。そうでない場合は、何を含めるべきか教えてください。助けてくれてありがとう、アンディ

4

2 に答える 2

0

したがって、この投稿をここでフォローして、タスクのアクティビティスタックを表示してください

私の活動スタックは、メインから脳の活動まで次のように出力されます(正しく)

Running activities (most recent first):
  Run #3: ActivityRecord{41cd3948 u0 com.trainer/.Brain}
  Run #2: ActivityRecord{41ca29a0 u0 com.trainer/.Main}
  Run #1: ActivityRecord{41a2c5d8 u0 com.cyanogenmod.trebuchet/.Launcher}

これまでのところすべてうまくいっていると思いますが、脳の活動から任意の pdf を起動すると、結果として得られる活動スタックは次のようになります。

      Run #5: ActivityRecord{4154ca00 u0 com.adobe.reader/.ARViewer}
  Run #4: ActivityRecord{41bcbcf8 u0 com.trainer/.Main}
  Run #3: ActivityRecord{41cd3948 u0 com.trainer/.Brain}
  Run #2: ActivityRecord{41ca29a0 u0 com.trainer/.Main}
  Run #1: ActivityRecord{41a2c5d8 u0 com.cyanogenmod.trebuchet/.Launcher}

何らかの理由で PDF を開くと、メイン アクティビティの別のバージョンが開始されますが、なぜこれが起こっているのかまったくわかりません。うまくいけば、これは他の誰かにとって何かを意味しますか?

これについて提供できる助けをありがとう....

于 2013-02-07T07:18:01.033 に答える
0

これを入手して、Brain のすべてのコードをコピーして、brain 2 という新しいアクティビティに貼り付けると、アプリが正常に動作します。理由はわかりませんが、きちんとした解決策ではありませんが、少なくとも機能します! プロジェクトのクリーニングを試みましたが、違いはありませんでした。少なくとも今はソートされています。

于 2013-02-07T15:39:40.187 に答える