Android - home screen lifecycle
I am developing android home screen, I seem to be having problems. Whenever I launch the app from this home screen, its lifecycle ends up being destroyed (I knew this because I was using LogCat and it prints my code in the OnDestroyed method). I only want this to be paused but not completely destroyed because I am running multiple long processes in oncreate. I only wanted onCreate to be called once when the device is loaded. In my case, because whenever my home screen launches the app, it gets destroyed. And whenever I press the HOME button it goes from the create -> on start -> on resume function. Below are my codes, can you state that I am doing something wrong. Thank.
My code when starting the application:
public void startAppByAppName(String appName) {
String mainActivity = "";
String packageString = "";
Intent intent = getPackageManager().getLaunchIntentForPackage(appName);
mainActivity = intent.getComponent().getClassName();
packageString = intent.getComponent().getPackageName();
intent.addCategory(Intent.CATEGORY_LAUNCHER);
intent.setComponent(new ComponentName(packageString, mainActivity));
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
My manifest:
<application
android:allowBackup="true"
android:icon="@drawable/home_icon"
android:label="@string/app_name"
android:theme="@style/AppTheme" android:persistent="true">
<activity
android:name="com.steven.welcomescreen.WelcomeScreenActivity"
android:launchMode="singleTask"
android:clearTaskOnLaunch="true"
android:stateNotNeeded="true"
android:screenOrientation="landscape"
android:theme="@android:style/Theme.Black.NoTitleBar">
<intent-filter>
<category android:name="android.intent.category.HOME"/>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
</application>
If there are some parts of my code that you want to clarify, just write below so that I can provide you with information. I really need help. Thank you very much.
source to share
No one has answered this question yet
Check out similar questions: