-1

I did it like this:

Start App into an inner activity named A --> lock screen --> wait for a long time to make sure that the app has been recycled --> unlock ,show the future activity A--> press Home button --> click the app icon on desktop --> start a new App --> press back --> return to A.

I wonder how it happens?

Syehunter
  • 27
  • 4
  • what is the question or what is the problem that you are facing. I think u need to take a look at android activity lifecycle – playmaker420 Jan 15 '16 at 06:31
  • @playmaker420 I mean that when I click the app icon, there should be only one program instance on the same phone, but now there are 2.It happens with the step I did in my question.I want to know how to solve this problem – Syehunter Jan 15 '16 at 08:59

1 Answers1

0

if you need solution try this

if (!isTaskRoot()
            && getIntent().hasCategory(Intent.CATEGORY_LAUNCHER)
            && getIntent().getAction() != null
            && getIntent().getAction().equals(Intent.ACTION_MAIN)) {

        finish();
        return;
    }

Here is some of the description from http://developer.android.com/guide/topics/manifest/activity-element.html: **

... a new instance of a "singleTop" activity may also be created to handle a new intent. However, if the target task already has an existing instance of the activity at the top of its stack, that instance will receive the new intent (in an onNewIntent() call); a new instance is not created. In other circumstances — for example, if an existing instance of the "singleTop" activity is in the target task, but not at the top of the stack, or if it's at the top of a stack, but not in the target task — a new instance would be created and pushed on the stack.

**

Jemo Mgebrishvili
  • 5,187
  • 7
  • 38
  • 63
  • Thanks for your answer. I've thought about this method but it says that I might run this in root activity in Mainfest, however the root is a SplashActivity which will finish when start the main. – Syehunter Jan 18 '16 at 03:53
  • In my project, I had same problem, splash were main activity and when I wrote this method into onCreate(), problem were solved. – Jemo Mgebrishvili Jan 18 '16 at 07:25