I’m locking (hangup) the phone manually when my activity is running. When I unlock my phone, OnCreate() is called once again. I’m going with a dialog and webservice hit in OnCreate(). So, when the phone is unlocked another dialog is raised, another webservice hit is called.
Finally what I need is stop calling onCreate() when phone is unlocked. Is there any way?
No 🙂
You cannot stop
onCreate()from being called. However you can set some flag inonSaveInstanceState()which is called before the application is paused. Then inonCreate()to read whether the flag is set and know whether the activity has not been created but recreated because of screen lock, app going in background, etc.Please, check:
ActivityLifecycle
There it is explained that
onCreate()might be called multiple times in various situations.P.S. You cannot also prevent this. Android (and in fact iOS and Windows Phone 7) will pause the application when in background.