问题描述
在默认的Android启动,pressing家,而在另一个活动将开始启动。 pressing回家了,而在发射器将重置为默认主屏幕页面。我不知道如何可以做到这一点。机器人发送相同的意图启动器是否在前台或没有。 Home键也无法由用户的应用程序被截获。
有没有办法来实现这一目标?
Correct.
Correct.
If a call to startActivity()
will result in the Intent
being delivered to an existing instance of the activity, a new instance is not created (by definition) and the existing instance is called with onNewIntent()
instead of onCreate()
.
In the case of a home screen, typically the activity that truly is the home screen will use android:launchMode="singleTask"
or android:launchMode="singleInstance"
in the manifest, such as:
<activity
android:name="Launcher"
android:launchMode="singleTask"
android:clearTaskOnLaunch="true"
android:stateNotNeeded="true"
android:theme="@style/Theme"
android:screenOrientation="nosensor"
android:windowSoftInputMode="stateUnspecified|adjustPan">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.HOME"/>
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.MONKEY" />
</intent-filter>
</activity>
(from an old launcher in the AOSP)
Then, the activity can implement onNewIntent()
to do something. In the case of the aforementioned old launcher, its onNewIntent()
includes:
if (!mWorkspace.isDefaultScreenShowing()) {
mWorkspace.moveToDefaultScreen();
}
This, presumably, animates the UI back to the default screen if the user is presently viewing some other screen within the set of screens managed by the home screen activity.
Another approach to trigger onNewIntent()
, instead of using android:launchMode
, is to do it selectively when you call startActivity()
, by including appropriate flags in the Intent
, such as FLAG_ACTIVITY_REORDER_TO_FRONT
.
这篇关于Android启动preSS家在发射进入默认屏幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!