android – Theme.NoDisplay创建了延迟

前端之家收集整理的这篇文章主要介绍了android – Theme.NoDisplay创建了延迟前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
使用Theme.NoDisplay主题时出现了一个奇怪的错误显示另一个活动非常慢!

我从通知中打开一个不可见的活动,然后根据意图操作打开一个新的活动.

如果我使用任何其他主题,如Theme.AppCompat,那么打开输入对话框需要大约300ms.使用Theme.NoDisplay主题,大约需要5秒钟!

如果我使用logcat,那么我可以看到InputActivity中的onCreate,onResume等在创建不可见活动后几毫秒被调用,但是直到它实际可见,它需要几秒钟.我不明白该主题如何创建该效果或如何解决它(不使用服务).

无形的活动:

<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,stopIntent,0);

在InvisibleActivity中的onCreate中,这称为:

Intent i = new Intent(getApplicationContext(),InputActivity.class);
startActivity(i);

解决方法

这是相当古老的,但如果有人想知道,this link会谈到为什么会这样:

PSA: The new requirement to immediately finish an activity if using
Theme.NoDisplay is not a regression,this has always been a
requirement of it (see
07001
for example).

The reason the platform in M is now crashing the app if it doesn’t use this is because not using it would prevIoUsly break in very subtle and mysterIoUs ways. For example,you would sometimes end up with your app ANRing for no reason.

原文链接:https://www.f2er.com/android/315016.html

猜你在找的Android相关文章