これで、問題が 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 activity
。FLAG_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
使用し、これをチェックして、この結果コードを受け取った場合は、アクティビティを呼び出します。setResult
RESULT_FINISH
onActivityResult()
result code
finish
details
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);
*/
}
}