• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Question for Activity Switching.

Hi All,

I want to know something more about Activity Switching.
Lets say we have four Activity. Activity A,B,C,D. User is navigating in this manner. A -> B -> C ->D.

Now I want to do something like this. Now user will go to Activity B. Its decided already. I want to jump to activity D to A on press of back button without creating new instance of B. I can use the method onBackPressed that I know. But the question is 'without creating new object' .

You can some other way too of doing this.
Please reply.
 
By clicking the back button it takes you to the previous Activity in the stack. You can override what the back button does.
 
Yes, But when I ovverride back button I have to write startActivity method for that and startActivity will create new instance. I dont want to create the newInstance
 
In AndroidManifest.xml you can set a tag in the Activity tag: android:launchMode="singleTop", this way, if A Activity is in the stack, it will bring that up instead of creating a new instance.
 
this is what I did
have a static boolean in Activity A [I'll call it "flag"]
let's say you are in D , and want to go back to activity B when something happened
just let flag = true;
and in C , onResume , if flag is true , then call finish();
this way you go back to where you want

it's kinda a work around .. but worked for me
 
Back
Top Bottom