Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Theme.NoDisplay creates strage delay

I've got a strange error when using the Theme.NoDisplay theme: It makes it extremely slow to show another activity!

I open an invisible activity from a notification, which in turn opens a new activity depending on the intent action.

If I use any other theme, like Theme.AppCompat, then it takes a around 300ms to open the input dialog. With the Theme.NoDisplay theme, it takes about 5 seconds!

If I use logcat, then I can see that onCreate, onResume, etc. in the InputActivity is called some milliseconds after the invisible activity is created, but until it actually is visible, it takes several seconds. I don't understand how that theme can create that effect or how to solve it (without using a service).

The invisible activity:

<activity
    android:name=".InvisibleActivity"
    android:excludeFromRecents="true"
    android:noHistory="true"
    android:launchMode="singleTask"
    android:taskAffinity=""
    android:theme="@android:style/Theme.NoDisplay"/>

The activity to open:

<activity
    android:name=".InputActivity"
    android:configChanges="locale"
    android:hardwareAccelerated="false"
    android:label="@string/lblAddTime"
    android:theme="@style/theme.Dialog"
    android:windowSoftInputMode="stateVisible|adjustResize" />

The intent from the notification:

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);

And in onCreate in InvisibleActivity, this is called:

Intent i = new Intent(getApplicationContext(), InputActivity.class);
startActivity(i);
like image 870
Mackan Avatar asked Jul 19 '14 22:07

Mackan


2 Answers

This is pretty old, but if any one wonders, this link talks about why this happens:

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 https://developer.android.com/reference/android/R.style.html#Theme_NoDisplay 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.

like image 85
mhashim6 Avatar answered Oct 26 '22 00:10

mhashim6


If there is someone looking for what to use instead of

android:theme="@android:style/Theme.NoDisplay"

use

android:theme="@style/TextAppearance.AppCompat.Display4"
like image 41
ZootHii Avatar answered Oct 26 '22 01:10

ZootHii