[英]Android can i avoid onCreate() being called?
I have two applications App-1 & App-2. 我有两个应用程序App-1和App-2。 App-2 has a button which will start App-1. App-2有一个将启动App-1的按钮。
The need is to behave like the following:- 需要表现为以下行为:-
onClick()
of the button in App-2 has the following code:- App-2中按钮的onClick()
具有以下代码:-
Intent i = new Intent(); 意图i = new Intent(); i.setAction("com.xyz"); i.setAction(“ com.xyz”); //resolves to activity A of App-1 i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK); //解析为App-1的活动A i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK); i.putExtra("x", "y"); i.putExtra(“ x”,“ y”); startActivity(i); startActivity(i);
After step-4, onCreate()
of activity A is called which is quite normal. 步骤4之后,将调用活动A的onCreate()
,这很正常。 But I want Android to bring the entire Activity Stack to be brought to the foreground, since App-1 is running & Android hasn't killed it.(Which is the same behavior if I had launched App-1 after step-2). 但是我希望Android能够将整个Activity Stack带到前台,因为App-1正在运行且Android并未杀死它(如果我在步骤2之后启动了App-1,这是相同的行为)。
I want activity C to be shown to the user. 我希望将活动C显示给用户。
Kindly help me if it is possible to do this. 如果可以的话,请帮我。
I have tried making activity A as singleTask & singleInstance. 我尝试将活动A设置为singleTask和singleInstance。 if i do that, only activity A is brought to the foreground which is not what i want. 如果我这样做,只会将活动A带到前台,这不是我想要的。
the snippet of App-1's manifest looks like below:- App-1清单的代码段如下所示:-
<activity android:name=".aa.a"
android:configChanges="orientation|keyboardHidden|locale"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoDisplay"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter>
<action android:name="com.x.y.z" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
FLAG_ACTIVITY_NEW_TASK informs Android to start a new task; FLAG_ACTIVITY_NEW_TASK通知Android开始新任务; the new task doesn't contain B & C, so don't expect any of them to be shown. 新任务不包含B&C,因此不要指望其中的任何一个显示。 Also, FLAG_ACTIVITY_CLEAR_TOP removes B & C, which is exactly opposite to what you want. 另外,FLAG_ACTIVITY_CLEAR_TOP会删除B和C,这与您想要的完全相反。
Try removing both flags. 尝试删除两个标志。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.