1. Download our Official Android App: Forums for Android!

Apps Question for Activity Switching.

Discussion in 'Android Development' started by satellitemundo, Jun 20, 2011.

  1. satellitemundo

    Thread Starter
    Rank:
    None
    Points:
    15
    Posts:
    29
    Joined:
    Aug 18, 2010

    Aug 18, 2010
    29
    0
    15
    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.
     

    Advertisement

  2. miXer

    miXer Android Enthusiast
    Rank:
    None
    Points:
    53
    Posts:
    313
    Joined:
    Aug 12, 2010

    Aug 12, 2010
    313
    51
    53
    Norway
    By clicking the back button it takes you to the previous Activity in the stack. You can override what the back button does.
     
  3. AndroidLab

    AndroidLab Lurker
    Rank:
    None
    Points:
    5
    Posts:
    5
    Joined:
    Jun 6, 2011

    [FONT=&quot]Maybe you could think to create Nodes and joke with BackButton...[/FONT]
     
  4. satellitemundo

    Thread Starter
    Rank:
    None
    Points:
    15
    Posts:
    29
    Joined:
    Aug 18, 2010

    Aug 18, 2010
    29
    0
    15
    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
     
  5. miXer

    miXer Android Enthusiast
    Rank:
    None
    Points:
    53
    Posts:
    313
    Joined:
    Aug 12, 2010

    Aug 12, 2010
    313
    51
    53
    Norway
    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.
     
  6. JiMMaR

    JiMMaR Android Enthusiast
    Rank:
    None
    Points:
    53
    Posts:
    363
    Joined:
    Jun 12, 2010

    Jun 12, 2010
    363
    57
    53
    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
     

Share This Page

Loading...