开发者

problem with going back to last activity via custom back button

开发者 https://www.devze.com 2023-04-05 12:45 出处:网络
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 :

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号