Guest User

Untitled

a guest
Sep 11th, 2015
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. @Override
  2. protected void onCreate(Bundle savedInstanceState) {
  3. super.onCreate(savedInstanceState);
  4. setContentView(R.layout.activity_main);
  5.  
  6. Log.i(TAG, "onCreate() from MainActivity");
  7.  
  8. session = new TempSession(this);
  9.  
  10. // check if logged in. If not, take the user back to login activity.
  11. session.checkLogin(); // <---- HERE
  12.  
  13. Toast.makeText(this, "logged in as " + session.getUsername(), Toast.LENGTH_SHORT).show();
  14.  
  15. // Prevents screen from turning off when in this Activity.
  16. getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
  17.  
  18. ....
  19.  
  20. public void checkLogin(){
  21. // Check login status
  22. if(!this.isLoggedIn() || getUsername() == null) {
  23. // user is not logged in redirect him to Login Activity
  24. Intent i = new Intent(context, LoginActivity.class);
  25.  
  26. // Closing all the Activities
  27. i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
  28.  
  29. // Add new Flag to start new Activity
  30. i.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
  31.  
  32. // Staring Login Activity
  33. context.startActivity(i);
  34. }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment