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.

相关文章

Android性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...