Move your code to onResume
@Override protected void onResume() { super.onResume(); MyMethod(); }
Check Action Lifecycle
http://developer.android.com/reference/android/app/Activity.html
protected void onResume ()
Called after onRestoreInstanceState (Bundle), onRestart () or onPause () so that your activity begins to interact with the user. This is a good place to start animating, opening devices with exclusive access (such as cameras), etc.
Keep in mind that onResume is not the best indicator that your activity is visible to the user; A system window, such as a key lock, may be in front. Use onWindowFocusChanged (boolean) to know exactly what your activity is visible to the user (for example, to resume the game).
Derived classes should move on to implementing the superclass of this method. If they do not, an exception will be thrown.
Raghunandan
source share