Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android check user logged in before, else start login activity

Tags:

android

login

I want the login activity to start when the user starts the app but has not logged in before. If a successful login has been completed before, the app will skip the login page and move to MainMenu.java. What I have now is:

    public class Login extends Activity implements OnClickListener, TaskCompleteCallback{       first_time_check();  ... @Override protected void onCreate(Bundle savedInstanceState) {     super.onCreate(savedInstanceState);     setContentView(R.layout.configure);      ...}  private boolean first_time_check() {         String first = mPreferences.getString("first", null);         if((first == null)){             Intent i = new Intent(Login.this, MainMenu.class);              startActivity(i);         }         return false;     }  ...         SharedPreferences.Editor editor = mPreferences.edit();         editor.putString("first", value);     ...          editor.commit();                  // Close the activity         Intent i = new Intent(Login.this, MainMenu.class);          startActivity(i);     }            

But I get FCs'. Is something wrong with how I implemented SharedPreferences?

like image 440
bunbun Avatar asked Jul 16 '11 15:07

bunbun


People also ask

How can I see my previous activity?

Android activities are stored in the activity stack. Going back to a previous activity could mean two things. You opened the new activity from another activity with startActivityForResult. In that case you can just call the finishActivity() function from your code and it'll take you back to the previous activity.

Which method is use for start activity in Android?

1.2. To start an activity, use the method startActivity(intent) . This method is defined on the Context object which Activity extends. The following code demonstrates how you can start another activity via an intent.


1 Answers

Your code just never calls that first_time_check(), thus the automatic forward in case of a returning user does not work.

You could in onCreate() do

protected void onCreate(Bundle savedInstanceState) {     super.onCreate(savedInstanceState);      first_time_check();      setContentView(R.layout.configure);      ...} 

So for a new user, first_time_check() would forward him to the login page, otherwise the current layout would be shown and he could continue on this page.

like image 160
Heiko Rupp Avatar answered Sep 19 '22 18:09

Heiko Rupp