Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
173 views
in Technique[技术] by (71.8m points)

android - Is there any way to have one and only one instance of each activity?

I'm finding that in my application, the user can get quite 'nested' in the various activities that are opened while the user is using the application.

For example:

  1. Main Menu
  2. Object List
  3. Object Details
  4. Object Edit
  5. Object Details
  6. Object Child Details
  7. Object Child Edit
  8. Object Child Details

Now, when the user presses back, it has to go through 'Object Child Details' twice (same object, when it is edited it returns to the detailed page), and the same thing happens for the 'Parent Object Details'.

Is there a way to reuse activities, if they are already open in the stack, and reorder them to the front? The only way I have seen is on activities with the launcher attribute. I believe I saw singleTask and singleTop.

If am supposed to be using these two attributes, singleTask and singleTop, how am I supposed to use them? When I tried to include them in the application, it made no difference. Do I also need to set a flag while launching the intent using startActivity?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

in Manifest Activity property you can give this parameter android:launchMode="singleInstance"

Read in more detail here http://developer.android.com/guide/topics/manifest/activity-element.html


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...