problem with going back to last activity via custom back button
I have a custom back button that for the time being does nothing other than going to the p开发者_StackOverflow中文版revious activity on the back stack. Heres the code for the button :
backButton.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
System.out.println("!!! BACK !!!");
finishActivity(0);
}
});
The problem is, its not working. There is simply no change.
Can anyone kindly tell me what I have done wrong here ? Thanks.
finishActivity finishes an activity that you had previously started with startActivityForResult(), it doesn't finish the activity you are currently in - finish() does that.
Use finish()
instead of finishActivity()
.
finishActivity()
forces an activity that you started via startActivityForResult()
to quit, it doesn't finish the current activity. You can also use onBackPressed()
, that just calls finish()
internally (see the default implementation), so it has the same effect. Useful if you override the back button behaviour though.
精彩评论