Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- Log.i(TAG, "onCreate() from MainActivity");
- session = new TempSession(this);
- // check if logged in. If not, take the user back to login activity.
- session.checkLogin(); // <---- HERE
- Toast.makeText(this, "logged in as " + session.getUsername(), Toast.LENGTH_SHORT).show();
- // Prevents screen from turning off when in this Activity.
- getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
- ....
- public void checkLogin(){
- // Check login status
- if(!this.isLoggedIn() || getUsername() == null) {
- // user is not logged in redirect him to Login Activity
- Intent i = new Intent(context, LoginActivity.class);
- // Closing all the Activities
- i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
- // Add new Flag to start new Activity
- i.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
- // Staring Login Activity
- context.startActivity(i);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment