Solution for opening two application instances at the android startup Portal

Source: Internet
Author: User

First, you can try to set some attributes for intent.


[Java]
Intent. addCategory (Intent. CATEGORY_LAUNCHER );
Intent. setFlags (Intent. FLAG_ACTIVITY_NEW_TASK | Intent. FLAG_ACTIVITY_RESET_TASK_IF_NEEDED );

If not, continue reading. Www.2cto.com


In my application, there is a button. You can click the button to start Netease news. Because I do not know the specific main Activity name of Netease news, the first thing I think of is to use the package name to start Netease news. The method for getting Netease news package name is simple. You can view it using android ddms. Package name: "com. netease. newsreader. activity ".

The click event of the button written for the first time is:


[Java]
Intent startapp = mContext. getPackageManager (). getLaunchIntentForPackage ("com. netease. newsreader. activity ");
Startapp. addCategory (Intent. ACTION_MAIN );
Startapp. addCategory (Intent. CATEGORY_LAUNCHER );
Startapp. setFlags (Intent. FLAG_ACTIVITY_NEW_TASK | Intent. FLAG_ACTIVITY_RESET_TASK_IF_NEEDED );
MContext. startActivity (startapp );

I thought it would be easy. Later tests showed that NetEase news entered by clicking my button was not the same as Netease news by clicking the built-in shortcuts of Netease news. I was wondering why I couldn't find it all the time. Later I began to suspect that it was the reason for Netease news. Finally, an accidental attempt found a solution to the problem.

[Java]
Intent intent = new Intent ("android. intent. action. MAIN ");
Intent. addCategory ("android. intent. category. LAUNCHER ");
Intent. setFlags (Intent. FLAG_ACTIVITY_NEW_TASK | Intent. FLAG_ACTIVITY_RESET_TASK_IF_NEEDED );
Intent. setComponent (ComponentName. unflattenFromString ("com. netease. newsreader. activity/. MainIndexActivity "));
MContext. startActivity (intent );

I believe everyone has found a different place. By the way, we can solve this problem by starting with the main activity of Netease news instead of using the package name.
As for how to know the main Activity of an application, there are many methods, which can be viewed by log filtering ActivityManager, or by decompiling.
Author: g475266696

Related Article

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.