title: Check if user is already logged in Parse - Android
body: <p>I am using parse to signup a user and login. I have completed those modules successfully. Now my doubt is that, where and how do I check if the user is already logged in. If the user is already logged in, show him the MainActivity else show him the HomeActivity.</p>
  
  <p>Currently I have the HomeActivity as my launcher in the <code>Manifest</code></p>
  
  <pre><code>&lt;activity
            android:name=".Activities.Home"
            android:label="@string/title_activity_home" &gt;
                  &lt;intent-filter&gt;
                      &lt;action android:name="android.intent.action.MAIN" /&gt;
  
                      &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
                  &lt;/intent-filter&gt;
              &lt;/activity&gt;
  </code></pre>
  
  <p>Then I have a Application class where I initialise the parse object.</p>
  
  <pre><code>   public class MyClass extends Application {
      public static Context context;
      @Override
      public void onCreate() {
          super.onCreate();
          context = getApplicationContext();
  
          Parse.initialize(this, "KEYS", "KEYS");
  
          if(ParseUser.getCurrentUser().isAuthenticated()){
              Intent intent = new Intent(context,MainActivity.class);
              intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
              startActivity(intent);
          }else{
              Intent intent = new Intent(context,Home.class);
              intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
              startActivity(intent);
          }
  
      }
  }
  </code></pre>
  
  <p>I am getting this error in the logcat</p>
  
  <pre><code>java.lang.RuntimeException: Unable to create application com.artqueen.aahaan.Aahaan: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean com.parse.ParseUser.isAuthenticated()' on a null object reference
              at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5255)
              at android.app.ActivityThread.access$1600(ActivityThread.java:182)
              at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1536)
              at android.os.Handler.dispatchMessage(Handler.java:102)
              at android.os.Looper.loop(Looper.java:145)
              at android.app.ActivityThread.main(ActivityThread.java:6141)
              at java.lang.reflect.Method.invoke(Native Method)
              at java.lang.reflect.Method.invoke(Method.java:372)
              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
       Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean com.parse.ParseUser.isAuthenticated()' on a null object reference
              at com.artqueen.aahaan.Aahaan.onCreate(Aahaan.java:33)
              at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1020)
              at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5252)
              at android.app.ActivityThread.access$1600(ActivityThread.java:182)
              at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1536)
              at android.os.Handler.dispatchMessage(Handler.java:102)
              at android.os.Looper.loop(Looper.java:145)
              at android.app.ActivityThread.main(ActivityThread.java:6141)
              at java.lang.reflect.Method.invoke(Native Method)
              at java.lang.reflect.Method.invoke(Method.java:372)
              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
  </code></pre>
  
  <p>How do I achieve this ? Thanks in advance.</p>