Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Single Instances of Activities

  1. #1
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,676
    Thanks
    25
    Thanked 329 Times in 305 Posts

    Default Single Instances of Activities

    I have a very specific program flow for my activities. There are two flows, which look like this:
    Flow 1)
    Main Activity - contains button to take you to the New Puzzle activity
    New Puzzle Activity - contains configuration information for the puzzle and a button which takes you to the Puzzle activity
    Puzzle Activity - simply contains an interactive puzzle, contains options menu item to bring you to the New Puzzle Activity
    Flow 2)
    Main Activity - contains button to load a previously saved puzzle and takes you to the Puzzle Activity
    Puzzle Activity - simply contains an interactive puzzle, contains options menu item to bring you to the New Puzzle Activity

    Only one puzzle can exist in memory at any given time, which means I would like to restrict the number of allowed Puzzle Activities in the stack to 1. This means I would also like to restrict the number of New Puzzle Activities in the stack to 1, since there would be no purpose to having 2 or more.

    I did a bit of research and came across the android:launchMode="singleTask" and "singleInstance", but the Android Developer guide warns "not recommended for general use" (<activity> | Android Developers).

    Would using these launch modes do what I want and would it be an ok thing to use, or is there a better way to do this?
    NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:

    When asking for help, please follow these guidelines to receive better and more prompt help:
    1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
    2. Give full details of errors and provide us with as much information about the situation as possible.
    3. Give us an example of what the output should look like when done correctly.

    Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/


  2. #2
    Forum VIP
    Join Date
    Jun 2011
    Posts
    317
    My Mood
    Bored
    Thanks
    47
    Thanked 89 Times in 74 Posts
    Blog Entries
    4

    Default Re: Single Instances of Activities

    I think what you are looking for is an Intent with the flag FLAG_ACTIVITY_REORDER_TO_FRONT

    Intent openPuzzelActivity = new Intent(PuzzelActivity.this, Main.class);
    openPuzzelActivity.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
    startActivity(openPuzzelActivity);


    From the docs:
    FLAG_ACTIVITY_REORDER_TO_FRONT - If set in an Intent passed to Context.startActivity(), this flag will cause the launched activity to be brought to the front of its task's history stack if it is already running.

Similar Threads

  1. Passing data between activities in android
    By okemwa in forum Android Development
    Replies: 0
    Last Post: April 3rd, 2014, 01:54 AM
  2. Activities.
    By TP-Oreilly in forum Android Development
    Replies: 4
    Last Post: January 23rd, 2012, 04:10 AM
  3. Replies: 3
    Last Post: April 11th, 2011, 09:51 PM
  4. [SOLVED] Help me with different activities in Java program
    By xyldon27 in forum Java Theory & Questions
    Replies: 10
    Last Post: June 9th, 2009, 09:42 AM