user2160008
user2160008

Reputation: 379

onDestroy is calling When phone screen Off

i created a sip call. When phone screen is turned on and if i receive any incoming call, everthing is OK. I mean that onStart() is called and onDestroy() is not called. So i am able answer the call. But When phone screen is off and an incoming call is received. i see that onStart() is called and onDestroy() is also being called. I see that android process automatically kills this activity.

This problem is not in android 2.3 version. i saw this in the latest version.

Any Solutions? my onDestroy() method should not be called. it should be called only when i come out of the activity.

Upvotes: 2

Views: 1620

Answers (4)

Lanile
Lanile

Reputation: 41

Yes, the problem occurs when using screen "Landscape" only, because the screen changes to "portrait" internally.

To prevent this, call onDestroy() in case screen goes ON or OFF.

  1. add to AndroidManifest.xml File with "orientation|screenSize" attribute.
  2. add onConfigurationChanged() method to your activity

AndroidManifest.xml

<activity
   …
   android:screenOrientation="landscape"
   android:configChanges="keyboardHidden|orientation|screenSize">

And add to your activity:

…
@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
}

Upvotes: 4

Brian
Brian

Reputation: 13583

Did you set your screen orientation as ScreenOrientation.LANDSCAPE_FIXED or ScreenOrientation.LANDSCAPE_SENSOR in onCreateEngineOptions()?

I found that onDestroy would be called when using ScreenOrientation.LANDSCAPE_FIXED. But if I use ScreenOrientation.PORTRAIT_FIXED, onDestroy is not called when turning screen off.

I'm still not clear about the reasons behind this problem, but I think this is a clue to solve it.

Upvotes: 0

siddharthsn
siddharthsn

Reputation: 1709

You can go check in your developer options(On your latest version device), if you have enabled the 'Don't keep Activities' option. You can disable it. This could be one reason why onDestroy() is being called only on your latest version device.

Upvotes: 0

Sandeep P
Sandeep P

Reputation: 4411

onDestroy method will call i your app is get force close or.. app is closed.. may be your app get closed by instance.. on onStop, onDestroy will call wen you press back button,. onDestroy wont call wen you press home button

Upvotes: 0

Related Questions