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?
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With