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