The XDA LG QPair Developer Challenge Voting Has Begun!

It seems like it was just yesterday that weannounced that we had paired up with LGto … more

Major Update for the Sony Smartwatch 2 Brings DND and More

With the wearables landscape now dominated by Android Wear and Pebble, its … more

How to Root Android Wear 5.0.1 Lollipop Devices – XDA TV

The Lollipop update for Android Wear devices has hit the market and people are … more

Android 5.0.2 and New Factory Images For Nexus 7 (Wi-Fi) Available

Android 5.0 is has been publicly available since early November, and the … more

Welcome to XDA

Search to go directly to your device's forum

Register an account

Unlock full posting privileges

Ask a question

No registration required
Post Reply

[Q] Backbutton in Acitivity

OP Auroratic

21st January 2014, 11:54 PM   |  #1  
Auroratic's Avatar
OP Member
Flag Austria
Thanks Meter: 0
 
45 posts
Join Date:Joined: Jun 2013
More
Hello,
I've created an app which consists of 2 Activities:
A1 and A2

In A1 is a button, which starts the A2:
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:
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 ?
22nd January 2014, 10:00 AM   |  #2  
SimplicityApks's Avatar
Senior Member
Flag Aachen
Thanks Meter: 337
 
346 posts
Join Date:Joined: May 2013
More
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.
22nd January 2014, 04:03 PM   |  #3  
Auroratic's Avatar
OP Member
Flag Austria
Thanks Meter: 0
 
45 posts
Join Date:Joined: Jun 2013
More
Quote:
Originally Posted by SimplicityApks

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

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..
22nd January 2014, 06:12 PM   |  #4  
SimplicityApks's Avatar
Senior Member
Flag Aachen
Thanks Meter: 337
 
346 posts
Join Date:Joined: May 2013
More
Quote:
Originally Posted by Auroratic

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.
23rd January 2014, 01:33 PM   |  #5  
Auroratic's Avatar
OP Member
Flag Austria
Thanks Meter: 0
 
45 posts
Join Date:Joined: Jun 2013
More
I don't get it, please provide some hints and/or code samples
23rd January 2014, 03:59 PM   |  #6  
SimplicityApks's Avatar
Senior Member
Flag Aachen
Thanks Meter: 337
 
346 posts
Join Date:Joined: May 2013
More
Quote:
Originally Posted by Auroratic

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:
 
Intent i = new Intent("com.yourpackage.app.name");
The Following User Says Thank You to SimplicityApks For This Useful Post: [ View ]
Post Reply Subscribe to Thread
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes