使用Theme.NoDisplay
主题时出现了一个奇怪的错误:它显示了另一个活动的速度非常慢!
我从通知中打开一个不可见的活动,然后根据意图操作打开一个新的活动。
如果我使用任何其他主题,例如Theme.AppCompat
,那么打开输入对话框需要大约300毫秒。使用Theme.NoDisplay
主题,大约需要5秒钟!
如果我使用logcat,那么我可以看到onCreate
中的onResume
,InputActivity
等在创建不可见活动后几毫秒被调用,但直到它实际上是可见,需要几秒钟。我不明白该主题如何创造这种效果或如何解决它(不使用服务)。
隐形活动:
<activity
android:name=".InvisibleActivity"
android:excludeFromRecents="true"
android:noHistory="true"
android:launchMode="singleTask"
android:taskAffinity=""
android:theme="@android:style/Theme.NoDisplay"/>
要开放的活动:
<activity
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, 0, stopIntent, 0);
在onCreate
InvisibleActivity
中,这称为:
Intent i = new Intent(getApplicationContext(), InputActivity.class);
startActivity(i);
答案 0 :(得分:1)
如果有人想用什么来代替
android:theme="@android:style/Theme.NoDisplay"
使用
android:theme="@style/TextAppearance.AppCompat.Display4"
答案 1 :(得分:0)
这已经很老了,但是如果有人想知道,this link谈到发生这种情况的原因:
PSA:如果使用,则必须立即完成一项活动的新要求 Theme.NoDisplay不是回归,这一直是 它的要求(请参阅 https://developer.android.com/reference/android/R.style.html#Theme_NoDisplay 例如)。
如果不使用M,平台现在会崩溃的原因 这是因为不使用它以前会变得非常微妙, 神秘的方式。例如,有时您最终会遇到 应用程式ANRing毫无原因。