Android different ways to start a problem resolution that causes the same activity to start repeatedly

Source: Internet
Author: User

There are several ways to open a program entry:

1. Shell command Open Run

2, launcher Standby interface operation

3. The status bar starts to run

4. Desktop Shortcut Run

5. Call run in software

6. Perform "open/Open" operation after installing software


If the user executes the "open/open" run immediately after installation, or runs the application with the ADB shell command, then click the Home key to suspend the program,

Then use another send launcher, which will then start a main program,

Causes the user to click many clicks to exit the program,


So what's the reason?

This is because intent processing mechanism is, first compare activity, then compare action, Flag, Bnds ... , before and after the two-way action is not the same,

One has launcher ACTION, one does not, so it will be considered to be starting two different intent.


So the question is, which is the best solution to the bug?

Haha, very simple: You can try to add parameters to the start activity item in the Androidmanifest.xml file:

Android:launchmode= "SingleInstance"  

The question comes again. Why is this line of code so magical, let's look at the principle of this line of code:

When a acitivty is set to singleinstance mode, the acitivity will have a unique task stack that will not be recreated once it is created.

It's all clear, right?


Of course there will be a little bit of sequela, if you are using Startactivityforresult:

Explains what Startactivityforresult:a-activity needs to perform some data operations in B-activtiy, and b-activity also returns the results of the operation data to A-activtiy

this time if you a-activity set it to singleinstance mode will not receive the data returned by B-activity, why:

Very simple, because the a-activity can not be re-created, will not execute callbacks, of course, it is not useful, hehe, the answer is complete.



Android different ways to start a problem resolution that causes the same activity to start repeatedly

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.