Attend XDA's Second Annual Developer Conference, XDA:DevCon 2014!
5,738,086 Members 54,562 Now Online
XDA Developers Android and Mobile Development Forum

[Q] Backbutton in Acitivity

Tip us?
 
Auroratic
Old
#1  
Auroratic's Avatar
Member - OP
Thanks Meter 0
Posts: 41
Join Date: Jun 2013
Location: Austria
Default [Q] Backbutton in Acitivity

Hello,
I've created an app which consists of 2 Activities:
A1 and A2

In A1 is a button, which starts the A2:
Code:
Select Code
Intent intent = new Intent();
            intent.setClassName(getPackageName(), getPackageName() + ".A2");
            startActivity(intent);
In A2 is a Button, which starts the A2 with different paramters:
Code:
Select Code
Intent intent = new Intent();
            intent.setClassName(getPackageName(), getPackageName() + ".A2");
            intent.putExtra("abc", "shsh");
            startActivity(intent);
And now, when I press the back-button in A2 with different parameters, I go to A1

How can I change this to go to A2 (without the "abc" parameter) and then, when I press the backbutton again, go to A1 ?
 
SimplicityApks
Old
#2  
SimplicityApks's Avatar
Senior Member
Thanks Meter 307
Posts: 287
Join Date: May 2013
Location: Aachen
Try passing the FLAG_ACTIVITY_NEW_TASK to the Intent starting the second A2 activity. If that doesn't work, you would need to override the onBackPressed() method and manually restart the first one.
 
Auroratic
Old
#3  
Auroratic's Avatar
Member - OP
Thanks Meter 0
Posts: 41
Join Date: Jun 2013
Location: Austria
Quote:
Originally Posted by SimplicityApks View Post
Try passing the FLAG_ACTIVITY_NEW_TASK to the Intent starting the second A2 activity.
Does not work

Is there no other simple solution?

Quote:
Originally Posted by SimplicityApks View Post
If that doesn't work, you would need to override the onBackPressed() method and manually restart the first one.
Im loading some stuff from a server in the first A2, so this would be useless..
 
SimplicityApks
Old
#4  
SimplicityApks's Avatar
Senior Member
Thanks Meter 307
Posts: 287
Join Date: May 2013
Location: Aachen
Quote:
Originally Posted by Auroratic View Post
Does not work

Is there no other simple solution?


Im loading some stuff from a server in the first A2, so this would be useless..
Found it, read this doc here. Don't have time to read into it right now, but you'll have to add the activity to the back stack somehow.
 
Auroratic
Old
#5  
Auroratic's Avatar
Member - OP
Thanks Meter 0
Posts: 41
Join Date: Jun 2013
Location: Austria
I don't get it, please provide some hints and/or code samples
 
SimplicityApks
Old
#6  
SimplicityApks's Avatar
Senior Member
Thanks Meter 307
Posts: 287
Join Date: May 2013
Location: Aachen
Quote:
Originally Posted by Auroratic View Post
I don't get it, please provide some hints and/or code samples
OK sorry, had a look at it again. Seems like you don't need to pass any flags:
Quote:
Note:*When a new instance of an activity is created, the user can press the*Back*button to return to the previous activity. But when an existing instance of an activity handles a new intent, the user cannot press the*Back*button to return to the state of the activity before the new intent arrived inonNewIntent()
so make sure that you haven't set any flags, and have the launch mode of the A2 activity set to default.
Also pass the class name during creation of the starting Intent instead of calling setClassName, like so:

Code:
Select Code
 
Intent i = new Intent("com.yourpackage.app.name");
The Following User Says Thank You to SimplicityApks For This Useful Post: [ Click to Expand ]
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


XDA PORTAL POSTS

XDA Xposed Tuesday: Blur Your System Notification Panel – XDA Developer TV

Listen, we love innovative applications and modules that … more

Android 4.4.3 Begins Rolling Out to European HTC One M8

Shortly after the USA Unlocked and Developer Editions of the HTC One M8 received the … more

Modernize Your Emails with Email Popup

SMS andHangouts messages likely won’t ever replace traditional Emails for more formal … more

Change Your Toast Notification Style with XToast

Android uses multipletypes of notifications. One of these isknown as a toast notification. … more