I have a question about android lifecycle in Corona Enterprise

Hello.
I have a question about android lifecycle in Corona Enterprise.
If I activate lock mode with pushing on/off button on usual activity called by corona activity.
Its happend always , the activitys lifecycle like this…

onPause -> onSaveInstanceState -> onStop -> onDestroy(isFinishing == false) -> onCreate -> onRestoreInstanceState -> onResume -> onPause

And then, when I back to activity , the lifecycle like this…

onResume -> onPause -> onSaveInstanceState -> onStop -> onDestroy(isFinishing == false) -> onCreate -> onRestoreInstanceState -> onResume

As you can see , everytime the activity destroyed, create, destroyed, create…
What is happening when activating/unactivating the locking mode ??
I never defined a job for this event.
This issue happened only with Corona Enterprise…
Actually the CoronaActivity different life cycle… just onPause and onStop… and then onResume…

Is the my problem? or Corona control the situation.

Please give me a advise.
Thank you.

[import]uid: 180717 topic_id: 34294 reply_id: 334294[/import]

First of all, Corona does not control the lifecycle of the activity. That is controlled by Android. Meaning that the onCreate(), onStart(), onResume(), onPause(), onStop(), and onDestroy() methods are all invoked by Android.

That said, the onDestroy() method is normally only called when your “back” out of the app. It should not be destroyed when suspended, except for the following reasons:

  1. The activity being displayed is eating up all memory on the device, causes Android to destroy your app’s activity.
  2. You have “Don’t keep activities” checked under “Developer Options” on your device, which is an Android 4.x setting. That setting will always destroy an activity when you suspend it.
  3. In your AndroidManifest.xml, you have set attribute “android:finishOnTaskLaunch” in the CoronaActivity tag. That may be causing your activity to get destroyed as well.

I suspect that you are running into #2 up above. Have a look at your device’s setting to see if this is checked on. You’ll want to check it off. [import]uid: 32256 topic_id: 34294 reply_id: 136385[/import]

Thank you for answering
I`ve checked all of given advises, but that have not solved yet.

  1. –> Even though the activity was just blank activity, it`s happening as same as before.
  2. –> the option already check off.
  3. –> I never used the attribute.

For more information, I want to show you AndroidManifest.xml and Activity source

@ AndroidManifest.xml
[html]

<?xml version="1.0" encoding="utf-8"?>

package="…"
android:versionCode=“1”
android:versionName=“1.0”>






android:label="@string/app_name"
android:hardwareAccelerated=“false”
android:icon="@drawable/icon"
android:debuggable=“true”>


android:screenOrientation=“landscape”
android:configChanges=“keyboardHidden|orientation|screenSize”
android:theme="@android:style/Theme.NoTitleBar.Fullscreen">












android:name=“com.uangel.corona.viewer.TestActivity”
android:configChanges=“keyboardHidden|orientation”
android:screenOrientation=“landscape”
android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >




[/html]

@ Function Class (calling Activity)
[java]
private class GoActivityFunction implements com.naef.jnlua.NamedJavaFunction{

@Override
public int invoke(LuaState luaState) {

Log.info(TAG, “no Error Checking start Content”);
com.ansca.corona.CoronaEnvironment.getCoronaActivity().getHandler().post(new Runnable() {
@Override
public void run() {
Intent intent = new Intent(com.ansca.corona.CoronaEnvironment.getCoronaActivity(), TestActivity.class);
com.ansca.corona.CoronaEnvironment.getCoronaActivity().startActivityForResult(intent, 0);
}
});

return 0;
}

@Override
public String getName() {
// TODO Auto-generated method stub
return “gotoactivity”;
}

}
[/java]
@ TestActivity
[java]
public class TestActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
Log.w(“lifecycle”, “[TestActivity] onCreate”);
super.onCreate(savedInstanceState);
}

@Override
protected void onDestroy() {
Log.w(“lifecycle”, "[TestActivity] onDestroy & isFinishing : " + isFinishing());
super.onDestroy();
}

@Override
protected void onPause() {
Log.w(“lifecycle”, “[TestActivity] onPause”);
super.onPause();
}

@Override
protected void onRestart() {
Log.w(“lifecycle”, “[TestActivity] onRestart”);
super.onRestart();
}

@Override
protected void onResume() {
Log.w(“lifecycle”, “[TestActivity] onResume”);
super.onResume();
}

@Override
protected void onStart() {
Log.w(“lifecycle”, “[TestActivity] onStart”);
super.onStart();
}

@Override
protected void onStop() {
Log.w(“lifecycle”, “[TestActivity] onStop”);
super.onStop();
}

@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
Log.w(“lifecycle”, “[TestActivity] onRestoreInstanceState”);
super.onRestoreInstanceState(savedInstanceState);
}

@Override
protected void onSaveInstanceState(Bundle outState) {
Log.w(“lifecycle”, “[TestActivity] onSaveInstanceState”);
super.onSaveInstanceState(outState);
}

}
[/java]

@ Log --> Getting off mode
[text]
12-28 14:38:01.823: W/lifecycle(2856): [TestActivity] onPause
12-28 14:38:01.833: W/lifecycle(2856): [TestActivity] onSaveInstanceState
12-28 14:38:01.833: W/lifecycle(2856): [TestActivity] onStop
12-28 14:38:02.348: W/lifecycle(2856): [TestActivity] onDestroy & isFinishing : false
12-28 14:38:02.433: W/lifecycle(2856): [TestActivity] onCreate
12-28 14:38:02.433: W/lifecycle(2856): [TestActivity] onStart
12-28 14:38:02.438: W/lifecycle(2856): [TestActivity] onRestoreInstanceState
12-28 14:38:02.438: W/lifecycle(2856): [TestActivity] onResume
12-28 14:38:02.453: W/lifecycle(2856): [TestActivity] onPause
[/text]

@ Log --> Getting back to Activity
[text]
12-28 14:38:45.508: W/lifecycle(2856): [TestActivity] onResume
12-28 14:38:45.813: W/lifecycle(2856): [TestActivity] onPause
12-28 14:38:45.813: W/lifecycle(2856): [TestActivity] onSaveInstanceState
12-28 14:38:45.813: W/lifecycle(2856): [TestActivity] onStop
12-28 14:38:45.813: W/lifecycle(2856): [TestActivity] onDestroy & isFinishing : false
12-28 14:38:45.818: W/lifecycle(2856): [TestActivity] onCreate
12-28 14:38:45.818: W/lifecycle(2856): [TestActivity] onStart
12-28 14:38:45.818: W/lifecycle(2856): [TestActivity] onRestoreInstanceState
12-28 14:38:45.818: W/lifecycle(2856): [TestActivity] onResume
[/text]
Please help me :frowning:
Thank you [import]uid: 180717 topic_id: 34294 reply_id: 136559[/import]

Your AndroidManifest.xml file is missing some settings.

You should add the [lua]android:launchMode=“singleTask”[/lua] attribute to the CoronaActivity derived activity tag, because it was designed to only support a single instance…
[lua] android:screenOrientation=“landscape”
android:configChanges=“keyboardHidden|orientation|screenSize”
android:launchMode=“singleTask”
android:theme="@android:style/Theme.NoTitleBar.Fullscreen">

[/lua]

You are also missing the “screenSize” setting in attribute [lua]android:configChanges[/lua] for your test activity. Without it, the activity will be automatically destroyed and re-created everytime the screen size changes, which can happen when returning from another activity and the top status bar is suddenly hidden/shown. It can also happen when you switch orientations, but only if your activity supports multiple orientations, which is not the case here.

In any case, your test activity should look like this…
[lua] android:configChanges=“keyboardHidden|orientation|screenSize”
android:screenOrientation=“landscape”
android:theme="@android:style/Theme.NoTitleBar.Fullscreen" />[/lua]
[import]uid: 32256 topic_id: 34294 reply_id: 136611[/import]

First of all, Corona does not control the lifecycle of the activity. That is controlled by Android. Meaning that the onCreate(), onStart(), onResume(), onPause(), onStop(), and onDestroy() methods are all invoked by Android.

That said, the onDestroy() method is normally only called when your “back” out of the app. It should not be destroyed when suspended, except for the following reasons:

  1. The activity being displayed is eating up all memory on the device, causes Android to destroy your app’s activity.
  2. You have “Don’t keep activities” checked under “Developer Options” on your device, which is an Android 4.x setting. That setting will always destroy an activity when you suspend it.
  3. In your AndroidManifest.xml, you have set attribute “android:finishOnTaskLaunch” in the CoronaActivity tag. That may be causing your activity to get destroyed as well.

I suspect that you are running into #2 up above. Have a look at your device’s setting to see if this is checked on. You’ll want to check it off. [import]uid: 32256 topic_id: 34294 reply_id: 136385[/import]

I`ve solved finally!
I really appreciate your help :slight_smile:
[import]uid: 180717 topic_id: 34294 reply_id: 136849[/import]

Thank you for answering
I`ve checked all of given advises, but that have not solved yet.

  1. –> Even though the activity was just blank activity, it`s happening as same as before.
  2. –> the option already check off.
  3. –> I never used the attribute.

For more information, I want to show you AndroidManifest.xml and Activity source

@ AndroidManifest.xml
[html]

<?xml version="1.0" encoding="utf-8"?>

package="…"
android:versionCode=“1”
android:versionName=“1.0”>






android:label="@string/app_name"
android:hardwareAccelerated=“false”
android:icon="@drawable/icon"
android:debuggable=“true”>


android:screenOrientation=“landscape”
android:configChanges=“keyboardHidden|orientation|screenSize”
android:theme="@android:style/Theme.NoTitleBar.Fullscreen">












android:name=“com.uangel.corona.viewer.TestActivity”
android:configChanges=“keyboardHidden|orientation”
android:screenOrientation=“landscape”
android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >




[/html]

@ Function Class (calling Activity)
[java]
private class GoActivityFunction implements com.naef.jnlua.NamedJavaFunction{

@Override
public int invoke(LuaState luaState) {

Log.info(TAG, “no Error Checking start Content”);
com.ansca.corona.CoronaEnvironment.getCoronaActivity().getHandler().post(new Runnable() {
@Override
public void run() {
Intent intent = new Intent(com.ansca.corona.CoronaEnvironment.getCoronaActivity(), TestActivity.class);
com.ansca.corona.CoronaEnvironment.getCoronaActivity().startActivityForResult(intent, 0);
}
});

return 0;
}

@Override
public String getName() {
// TODO Auto-generated method stub
return “gotoactivity”;
}

}
[/java]
@ TestActivity
[java]
public class TestActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
Log.w(“lifecycle”, “[TestActivity] onCreate”);
super.onCreate(savedInstanceState);
}

@Override
protected void onDestroy() {
Log.w(“lifecycle”, "[TestActivity] onDestroy & isFinishing : " + isFinishing());
super.onDestroy();
}

@Override
protected void onPause() {
Log.w(“lifecycle”, “[TestActivity] onPause”);
super.onPause();
}

@Override
protected void onRestart() {
Log.w(“lifecycle”, “[TestActivity] onRestart”);
super.onRestart();
}

@Override
protected void onResume() {
Log.w(“lifecycle”, “[TestActivity] onResume”);
super.onResume();
}

@Override
protected void onStart() {
Log.w(“lifecycle”, “[TestActivity] onStart”);
super.onStart();
}

@Override
protected void onStop() {
Log.w(“lifecycle”, “[TestActivity] onStop”);
super.onStop();
}

@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
Log.w(“lifecycle”, “[TestActivity] onRestoreInstanceState”);
super.onRestoreInstanceState(savedInstanceState);
}

@Override
protected void onSaveInstanceState(Bundle outState) {
Log.w(“lifecycle”, “[TestActivity] onSaveInstanceState”);
super.onSaveInstanceState(outState);
}

}
[/java]

@ Log --> Getting off mode
[text]
12-28 14:38:01.823: W/lifecycle(2856): [TestActivity] onPause
12-28 14:38:01.833: W/lifecycle(2856): [TestActivity] onSaveInstanceState
12-28 14:38:01.833: W/lifecycle(2856): [TestActivity] onStop
12-28 14:38:02.348: W/lifecycle(2856): [TestActivity] onDestroy & isFinishing : false
12-28 14:38:02.433: W/lifecycle(2856): [TestActivity] onCreate
12-28 14:38:02.433: W/lifecycle(2856): [TestActivity] onStart
12-28 14:38:02.438: W/lifecycle(2856): [TestActivity] onRestoreInstanceState
12-28 14:38:02.438: W/lifecycle(2856): [TestActivity] onResume
12-28 14:38:02.453: W/lifecycle(2856): [TestActivity] onPause
[/text]

@ Log --> Getting back to Activity
[text]
12-28 14:38:45.508: W/lifecycle(2856): [TestActivity] onResume
12-28 14:38:45.813: W/lifecycle(2856): [TestActivity] onPause
12-28 14:38:45.813: W/lifecycle(2856): [TestActivity] onSaveInstanceState
12-28 14:38:45.813: W/lifecycle(2856): [TestActivity] onStop
12-28 14:38:45.813: W/lifecycle(2856): [TestActivity] onDestroy & isFinishing : false
12-28 14:38:45.818: W/lifecycle(2856): [TestActivity] onCreate
12-28 14:38:45.818: W/lifecycle(2856): [TestActivity] onStart
12-28 14:38:45.818: W/lifecycle(2856): [TestActivity] onRestoreInstanceState
12-28 14:38:45.818: W/lifecycle(2856): [TestActivity] onResume
[/text]
Please help me :frowning:
Thank you [import]uid: 180717 topic_id: 34294 reply_id: 136559[/import]

Your AndroidManifest.xml file is missing some settings.

You should add the [lua]android:launchMode=“singleTask”[/lua] attribute to the CoronaActivity derived activity tag, because it was designed to only support a single instance…
[lua] android:screenOrientation=“landscape”
android:configChanges=“keyboardHidden|orientation|screenSize”
android:launchMode=“singleTask”
android:theme="@android:style/Theme.NoTitleBar.Fullscreen">

[/lua]

You are also missing the “screenSize” setting in attribute [lua]android:configChanges[/lua] for your test activity. Without it, the activity will be automatically destroyed and re-created everytime the screen size changes, which can happen when returning from another activity and the top status bar is suddenly hidden/shown. It can also happen when you switch orientations, but only if your activity supports multiple orientations, which is not the case here.

In any case, your test activity should look like this…
[lua] android:configChanges=“keyboardHidden|orientation|screenSize”
android:screenOrientation=“landscape”
android:theme="@android:style/Theme.NoTitleBar.Fullscreen" />[/lua]
[import]uid: 32256 topic_id: 34294 reply_id: 136611[/import]

I`ve solved finally!
I really appreciate your help :slight_smile:
[import]uid: 180717 topic_id: 34294 reply_id: 136849[/import]

is there a way to change launchMode in build settings? I’m having trouble launching the app after download from Google Play so I wanted to try standard instead of singleTask. I’m on a mac and having trouble using APK Manager; I can decompile but can’t re-compile with it.

thanks!

I’m getting in adb logcat:

07-19 14:06:41.117 15232 15243 V Corona  : > Class.forName: network.LuaLoader

07-19 14:06:41.117 15232 15243 V Corona  : < Class.forName: network.LuaLoader

07-19 14:06:41.117 15232 15243 V Corona  : Loading via reflection: network.LuaLoader

07-19 14:06:41.117 15232 15243 I Corona  : Platform: DROID X2 / ARM / 2.3.5 / NVIDIA Tegra / OpenGL ES 2.0 / 2014.2345

07-19 14:06:41.167 15232 15243 V Corona  : > Class.forName: CoronaProvider.licensing.google.LuaLoader

07-19 14:06:41.177 15232 15243 V Corona  : < Class.forName: CoronaProvider.licensing.google.LuaLoader

07-19 14:06:41.637 15232 15243 V Corona  : Loading via reflection: CoronaProvider.licensing.google.LuaLoader

no errors as far as I can see, but all I see is a blue menu bar with app name. a gradient grey area with a blank progress bar, and nothing happens…my client wants this launched.

Are you using a Google Play “expansion file”?

Because you will see an expansion file download screen when testing your app that resembles this.  In the past, it would usually take a few hours for Google’s servers to realize the new expansion file you’ve uploaded with your APK before you can test it.  Or this might indicate that you’re missing required permissions or a licensing config problem…

   http://docs.coronalabs.com/guide/basics/configSettings/index.html#app-licensing

   http://docs.coronalabs.com/guide/distribution/buildSettings/index.html#expansion-files

is there a way to change launchMode in build settings? I’m having trouble launching the app after download from Google Play so I wanted to try standard instead of singleTask. I’m on a mac and having trouble using APK Manager; I can decompile but can’t re-compile with it.

thanks!

I’m getting in adb logcat:

07-19 14:06:41.117 15232 15243 V Corona  : > Class.forName: network.LuaLoader

07-19 14:06:41.117 15232 15243 V Corona  : < Class.forName: network.LuaLoader

07-19 14:06:41.117 15232 15243 V Corona  : Loading via reflection: network.LuaLoader

07-19 14:06:41.117 15232 15243 I Corona  : Platform: DROID X2 / ARM / 2.3.5 / NVIDIA Tegra / OpenGL ES 2.0 / 2014.2345

07-19 14:06:41.167 15232 15243 V Corona  : > Class.forName: CoronaProvider.licensing.google.LuaLoader

07-19 14:06:41.177 15232 15243 V Corona  : < Class.forName: CoronaProvider.licensing.google.LuaLoader

07-19 14:06:41.637 15232 15243 V Corona  : Loading via reflection: CoronaProvider.licensing.google.LuaLoader

no errors as far as I can see, but all I see is a blue menu bar with app name. a gradient grey area with a blank progress bar, and nothing happens…my client wants this launched.

Are you using a Google Play “expansion file”?

Because you will see an expansion file download screen when testing your app that resembles this.  In the past, it would usually take a few hours for Google’s servers to realize the new expansion file you’ve uploaded with your APK before you can test it.  Or this might indicate that you’re missing required permissions or a licensing config problem…

   http://docs.coronalabs.com/guide/basics/configSettings/index.html#app-licensing

   http://docs.coronalabs.com/guide/distribution/buildSettings/index.html#expansion-files