Theien
Aspiring developer
Profile
Posts: 33
Reg: Dec 31, 2012
Colorado Spring...
9,780
12/17/13 01:04 PM (11 years ago)

Press Back Again to Exit

Doest anyone have any suggestions on where I can add this code snippet so it only works on my root activity? http://samadmalik.com/press-back-key-exit/ The problem I'm running into is I'm a bit confused to where the code needs to go. My app is setup so that my root activity is Menu Buttons, which extends BT_fragment, so adding the code snippet there won't work.
 
Jake Chasan
Veteran developer
Profile
Posts: 1685
Reg: May 13, 2011
location unknow...
29,650
like
12/18/13 09:42 AM (11 years ago)
Does this perform the same function as the home button? You should be able to put it inside the main activity. This is due to "Late-Binding" of overridden methods. The compiler does not compile these methods until it finds the most recent one (in the lowest extended class) Search through the project for where the back button is initialized (possibly in BT_activity?) and try to put the code there. Does this help? Jake
 
Theien
Aspiring developer
Profile
Posts: 33
Reg: Dec 31, 2012
Colorado Spring...
9,780
like
12/18/13 10:16 AM (11 years ago)
Well I found public void onBackPressed() in BT_activity_host.java and when I add the code there then every time the back button is pressed the toast message comes up. I only want it to come up on my Menu Buttons root activity.
 
CMCOFFEE
Android Fan
Profile
Posts: 2017
Reg: Jan 04, 2013
Amarillo, Texas
26,670
like
12/19/13 08:20 PM (11 years ago)
when you put it in BT_activity_host.java, it will show up in every screen. put the backOnPressed method in the class you want it to show up in
 

Login + Screen Name Required to Post

pointerLogin to participate so you can start earning points. Once you're logged in (and have a screen name entered in your profile), you can subscribe to topics, follow users, and start learning how to make apps like the pros.