I have an application which utilizes a splash screen and a choice screen, as depicted in the following manifest:
<application
android:name="com.example.CoolApp"
android:label="@string/app_name"
android:icon="@drawable/app_icon_debug"
android:theme="@style/Theme.NoBackground">
<activity
android:name="com.example.Splash"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:noHistory="true"
android:launchMode="singleTop">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data android:scheme="coolappscheme"/>
</intent-filter>
</activity>
<activity
android:name="com.example.ChoiceActivity"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateHidden"/>
</application>
The splash screen shows for about 2 seconds, and then navigates to the ChoiceActivity
via the following code:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
... some stuff for showing the Splash screen ...
Thread mythread = new Thread() {
@Override
public void run() {
try {
.. animation stuff for fading in ...
while (splashActive && ms < splashTime) {
if(!paused)
ms=ms+100;
sleep(100);
}
} catch(Exception e) {
} finally {
Intent intent = new Intent(Splash.this, ChoiceActivity.class);
startActivity(intent);
}
}
};
Now, clearly there are a number of things wrong with this code (starting with why the author decided to use a separate Thread
instead of an AsyncTask
. However, putting that stuff aside for the moment, if the user performs the following actions:
- Launch the application & see the splash screen.
- Force the application into the background (e.g. the user receives a phone call, or maybe just hits the 'home' button).
Then, when the Thread
completes (i.e. the finally
block is reached and the Intent
is created), the new ChoiceActivity
is created, but it also brings the application to the foreground. I want to disable this behavior. That is, I want the activity to be loaded, but the application to remain in the background. If that's not possible, then I want the application to delay loading of the new Activity
(//any// new Activity
) until after the Application has been resumed.
How can I achieve this?