質問

I am opening new activity on button click of one activity. New Activity contains image button named go back. Now I want that when anyone click on back button of mobile device, it fires onPause or say close the application but when anyone clicks on go back image button, application does not fire onPause and it goes on last activity. How to do it ?

役に立ちましたか?

解決

If you have called finish() in your first activity while coming to this second activity and if you want to go to first activity again on click event of "go back" button in second activity, then you need to call an Intent to go from second activity to first activity. But if you do not call finish() in your first activity while coming to this second activity and you want to go to first activity again on click event of "go back" button in second activity then simply call finish() on click event of "go back" button in second activity.

他のヒント

I saw your code from your other question, so you need to remove the finish() from onPause and add finish() to your "go back" button listener.

Do not call finish() if you want to keep it on the stack (in order to go back).

Example:

  1. Activity A starts Activity B, which starts Activity C. (no finish() called yet)
  2. Then when you go back from C, call finish() and you will see Activity B.
  3. Then when you go back from B, call finish() and you will see Activity A.

This is how you can pass values between different activities.

 Intent i = new Intent(A.this, B.class); 
 i.putExtra("numbers", array); 
 startActivity(i);
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top