Unable to load android view when trying to load an app from background to foreground
<p>I am new to android. I am developing an android app which is location based (capturing users location coordinates). In my app, I have a timer which runs a particular method to flush my location coordinates from sqlite database to server (through a web service call).</p>

<p>Please find my following code which has a timer onCreate view:</p>

<pre><code>Timer itsLocationTimer;

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
myLocationTimer();
}

private void myLocationTimer()
{
long flushDuration = 10000;
try 
{
    itsLocationTimer = new Timer();
    itsLocationTimer.schedule(new TimerTask() 
    {           
    @Override
        public void run() {
         TimerMethod();
    }
     }, 0, flushDuration);
} 
catch (JSONException e) 
{
    e.printStackTrace();
}
}

private void TimerMethod()
{
     sendLocationCoordinatesToServer();
}
</code></pre>

<p>When I run my app in foreground mode, I have no issues in location triggering or sending them to server (using my timer).</p>

<p>Now I switched my app to background mode and kept it running for few minutes. </p>

<p>On switching my app from background to foreground, I was unable to load my view. My app crashed. </p>

<p>It displayed the following message in logcat:</p>

<pre><code>09-28 18:12:51.476: D/dalvikvm(7394): GC_EXTERNAL_ALLOC freed 70K, 48% free 2847K/5379K, external 499K/517K, paused 136ms
09-28 18:12:51.539: D/AndroidRuntime(7394): Shutting down VM
09-28 18:12:51.539: W/dalvikvm(7394): threadid=1: thread exiting with uncaught exception (group=0x40018578)
09-28 18:12:51.554: E/AndroidRuntime(7394): FATAL EXCEPTION: main
09-28 18:12:51.554: E/AndroidRuntime(7394): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.org.myApp/com.org.myApp.view.HomeView}: java.lang.NullPointerException
09-28 18:12:51.554: E/AndroidRuntime(7394):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
09-28 18:12:51.554: E/AndroidRuntime(7394):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
09-28 18:12:51.554: E/AndroidRuntime(7394):     at android.app.ActivityThread.access$1500(ActivityThread.java:117)
09-28 18:12:51.554: E/AndroidRuntime(7394):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
09-28 18:12:51.554: E/AndroidRuntime(7394):     at android.os.Handler.dispatchMessage(Handler.java:99)
09-28 18:12:51.554: E/AndroidRuntime(7394):     at android.os.Looper.loop(Looper.java:130)
09-28 18:12:51.554: E/AndroidRuntime(7394):     at android.app.ActivityThread.main(ActivityThread.java:3687)
09-28 18:12:51.554: E/AndroidRuntime(7394):     at java.lang.reflect.Method.invokeNative(Native Method)
09-28 18:12:51.554: E/AndroidRuntime(7394):     at java.lang.reflect.Method.invoke(Method.java:507)
09-28 18:12:51.554: E/AndroidRuntime(7394):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
09-28 18:12:51.554: E/AndroidRuntime(7394):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
09-28 18:12:51.554: E/AndroidRuntime(7394):     at dalvik.system.NativeStart.main(Native Method)
09-28 18:12:51.554: E/AndroidRuntime(7394): Caused by: java.lang.NullPointerException
09-28 18:12:51.554: E/AndroidRuntime(7394):     at com.org.myApp.view.cub.HomeView.onCreate(HomeView.java:90)
09-28 18:12:51.554: E/AndroidRuntime(7394):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
09-28 18:12:51.554: E/AndroidRuntime(7394):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
09-28 18:12:51.554: E/AndroidRuntime(7394):     ... 11 more
</code></pre>

<p>Can any one please suggest me where the issue is? Why my app is crashed when switching it from background to foreground. </p>

<p>Any suggestions please? Thank you.</p>
