使用Theme.NoDisplay主题时出现了一个奇怪的错误:显示另一个活动非常慢!
我从通知中打开一个不可见的活动,然后根据意图操作打开一个新的活动.
如果我使用任何其他主题,如Theme.AppCompat,那么打开输入对话框需要大约300ms.使用Theme.NoDisplay主题,大约需要5秒钟!
如果我使用logcat,那么我可以看到InputActivity中的onCreate,onResume等在创建不可见活动后几毫秒被调用,但是直到它实际可见,它需要几秒钟.我不明白该主题如何创建该效果或如何解决它(不使用服务).
无形的活动:
android:name=".InvisibleActivity"
android:excludeFromRecents="true"
android:noHistory="true"
android:launchMode="singleTask"
android:taskAffinity=""
android:theme="@android:style/Theme.NoDisplay"/>
要打开的活动:
android:name=".InputActivity"
android:configChanges="locale"
android:hardwareAccelerated="false"
android:label="@string/lblAddTime"
android:theme="@style/theme.Dialog"
android:windowSoftInputMode="stateVisible|adjustResize" />
通知的意图:
Intent stopIntent = new Intent(context,InvisibleActivity.class);
stopIntent.setAction(InvisibleActivity.STOP_TIMER);
stopIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent pStopIntent = PendingIntent.getActivity(context,stopIntent,0);
在InvisibleActivity中的onCreate中,这称为:
Intent i = new Intent(getApplicationContext(),InputActivity.class);
startActivity(i);