0

私のアプリでは、ホーム、リスト、詳細という名前の3つの主要なアクティビティがあります

私のナビゲーションの初回は次のようになりますName -> List -> Details

詳細ページでユーザーがオプションを選択すると、同じアクティビティをもう一度呼び出して新しい詳細を表示します。これがn回続きます。

詳細ページには、3 つの重要なボタンがあります。1. back, 2. List, 3. Home

詳細ページからの私の問題は

1. when List button is clicked i have to move on to the List Activity, and by pressing back button from List Activity i need to show Home page, not Details Page

2. when Home button is clicked i have to move on to the Home Activity, and by pressing back button from Home Activity i need the app to get closed.

3. back -> 
   a. when the user comes first time to the Details page, by pressing back button he needs to move to List Activity

   b. after loading the Details activity again and again, by pressing the back button user can move on to previous Details, here the condition is while starting the activity i should not give finish(), because this causes the data to get loaded of a long time

上記の問題をどのように克服するか

4

2 に答える 2

1

これで、問題が 1 つずつ表示されます。

1. when List button is clicked i have to move on to the List Activity, and by pressing back button from List Activity i need to show Home page, not Details Page

これで、次の方法でこれを実現できます。

他の活動に行くときはいつでも電話finish()しないでください。home or list activity

このようにして、Home activity常にスタックに存在します。したがって、アクティビティを前面に出す必要があるため、フラグを設定するか、フラグを設定してstartActivity呼び出しHome activityますList activityFLAG_ACTIVITY_REORDER_TO_FRONT

2. when Home button is clicked i have to move on to the Home Activity, and by pressing back button from Home Activity i need the app to get closed.
3. back -> 
   a. when the user comes first time to the Details page, by pressing back button he needs to move to List Activity
b. after loading the Details activity again and again, by pressing the back button user can move on to previous Details, here the condition is while starting the activity i should not give finish(), because this causes the data to get loaded of a long time

繰り返しますが、これは、上記のようにフラグを設定して Home の startActivity と同じものを使用することで実行できます。

また

startActivityForResult()からdetails他のアクティビティまで使用します。Homeしたがって、 (すべての) アクティビティからアクティビティに戻りたい場合は、ex.: としてDetails使用し、これをチェックして、この結果コードを受け取った場合は、アクティビティを呼び出します。setResultRESULT_FINISHonActivityResult()result codefinishdetails

This way, all your Details activity will get finished.

そしてHome活動から。を押すと、すべてのアクティビティが終了 finish()するため、アプリが閉じられます。(make sure all your activities are calling finish at some point of time.)

編集:

から移動する場合Home > List > Detailsの問題は次のとおりです。

1. when List button is clicked from details activity, i have to move on to the List Activity, and by pressing back button from List Activity i need to show Home page, not Details Page.

activity のいずれかに対して finish() を呼び出さない場合、これは機能しますHome > List > Details

これで、Details から Details を何度も呼び出すことができます。このために、私が提案したのはダミー コードです。

    public class Details extends Activity{

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        /*
         * If user presses back button, handle it like this:
         */
        if(requestCode == REQUEST_DETAILS) {
            if(resultCode == RESULT_FINISH) {
                finish();
            }
        }
        // In this way all your Details Activity will get finished.
    }

    @Override
    public void onBackPressed() {
        super.onBackPressed();
        /*
         * If user presses back button, call following:
         * 
         * set some flag as TRUE, ex.: 
         * 
         * flagIsFinishing = true;
         * 
         * setResult(RESULT_FINISH);
         * finish()
         */
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        /*
         * if(flagIsFinishing) { 
         *      setResult(RESULT_FINISH);
         *      finish();
         * }
         * 
         */
    }

    @Override
    protected void onResume() {
        super.onResume();
        /*
         * On selecting any option call Details activity like
         * 
         * startActivityForResult(intent, REQUEST_DETAILS);
         */
    }
}
于 2012-09-12T09:20:04.730 に答える
0

フラグを使用して問題を解決しましたOnResume()

詳細ページList button is clicked i am calling onBackPressed();で、その時点でブール値フラグを true に設定しています。

デフォルトでは、前のアクティビティを取得Detail Activity is called する場合。first timeback toList Activity

Detail activity is called for n number of timesおよびリスト ボタンがクリックされ、ブール値が true の場合、in ionResumeで関数が呼び出され、onBackPressed();取得されます。moved to the List Activity

于 2012-09-12T11:16:30.437 に答える