title: If apps got login already goto main activty else go to login page in android
body: <p>Hai guys greetings to all ...
   Am New To Android Field..I created New Android apps Using  Login and registeration screen... My Question Is I want If my apps got login by user already goto menu activty else go to login page in android.. Please Help Me By Giving Sample coding or idea..Thanks In Advance..</p>
  
  <p>This Is The Code am using. for My Qs , But its not Working..</p>
  
  <pre><code> package com.example.android_todist;
   import java.util.logging.Handler;
    import java.util.regex.Matcher;
    import java.util.regex.Pattern;
    import android.os.Handler;
    import android.app.Activity;
   import android.app.Dialog;
    import android.content.Context;
    import android.content.Intent;
   import android.content.SharedPreferences;
    import android.content.SharedPreferences.Editor;
   import android.os.Bundle;
    import android.preference.PreferenceManager;
     import android.support.v7.app.ActionBarActivity;
     import android.view.KeyEvent;
      import android.view.View;
    import android.widget.Button;
     import android.widget.EditText;
      import android.widget.ImageButton;
     import android.widget.TextView;
       import android.widget.Toast;
  
  public class SplashActivity extends Activity {
  Intent intent;
  String userName,password;
    SharedPreferences pref;
      Editor editor;
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.splash_screen);
       pref = PreferenceManager.getDefaultSharedPreferences(this);
    String storedUsername = pref.getString(userName, "");
   String storedPassword = pref.getString(password, ""); //return nothing if no pass       saved
  if (!storedUsername .equalsIgnoreCase("") || !storedPassword .equalsIgnoreCase("")) {
  Intent intent  = new Intent(this, Todist1.class);
      startActivity(intent);
      finish();
  
  }else {
      Intent  intent  = new Intent(this, Login.class);
      startActivity(intent);
     }
  
   new Handler().postDelayed(new Runnable() {
    @Override
          public void run() {
  
              startActivity(intent);
              finish();
          }
      }, 3000);
  
  }
  </code></pre>
  
  <p>}</p>
  
  <p>it will redirect to main page . but If the new user open My apps it will also redirect to main page cant able to get login page..</p>
  
  <p>This Is My Error log..:</p>
  
  <pre><code>   07-24 04:21:36.135: E/AndroidRuntime(1080): FATAL EXCEPTION: main
     07-24 04:21:36.135: E/AndroidRuntime(1080): java.lang.NullPointerException
     07-24 04:21:36.135: E/AndroidRuntime(1080):  at   
     android.app.Instrumentation.execStartActivity(Instrumentation.java:1410)
  
    07-24 04:21:36.135: E/AndroidRuntime(1080):   at 
    android.app.Activity.startActivityForResult(Activity.java:3370)
    07-24 04:21:36.135: E/AndroidRuntime(1080):   at   
    android.app.Activity.startActivityForResult(Activity.java:3331)
    07-24 04:21:36.135: E/AndroidRuntime(1080):   at 
    android.app.Activity.startActivity(Activity.java:3566)
    07-24 04:21:36.135: E/AndroidRuntime(1080):   at
    android.app.Activity.startActivity(Activity.java:3534)
    07-24 04:21:36.135: E/AndroidRuntime(1080):   at   
          com.example.android_todist.SplashActivity$1.run(SplashActivity.java:50)
  
    07-24 04:21:36.135: E/AndroidRuntime(1080):   at 
    android.os.Handler.handleCallback(Handler.java:725)
    07-24 04:21:36.135: E/AndroidRuntime(1080):   at 
    android.os.Handler.dispatchMessage(Handler.java:92)
    07-24 04:21:36.135: E/AndroidRuntime(1080):   at  
    android.os.Looper.loop(Looper.java:137)
    07-24 04:21:36.135: E/AndroidRuntime(1080):   at  
    android.app.ActivityThread.main(ActivityThread.java:5041)
    07-24 04:21:36.135: E/AndroidRuntime(1080):   at  
    java.lang.reflect.Method.invokeNative(Native Method)
   07-24 04:21:36.135: E/AndroidRuntime(1080):    at
  
  java.lang.reflect.Method.invoke(Method.java:511)
  07-24 04:21:36.135: E/AndroidRuntime(1080):     at 
   com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
  07-24 04:21:36.135: E/AndroidRuntime(1080):     at  
  com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
  07-24 04:21:36.135: E/AndroidRuntime(1080):     at 
  dalvik.system.NativeStart.main(Native Method)
  </code></pre>