0

Pardon me as I am quite new to android. I am trying to launch a login page(Login Activity) whenever my application awakes from sleep mode. Example: my application goes into sleep mode when it is in my Main Activity. When it awakes, i want to set the activity as Login Activity instead of returning back to Main Activity. I read something about onResume and i tried but my application crashed. Any advice or suggestion is greatly appreciated. Thank you in advance.

Main Activity

public class UserMainActivity extends TabActivity {
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_user_main);

    TabHost tabHost = getTabHost();

    // List view
    TabSpec list = tabHost.newTabSpec("List view");
    list.setIndicator("List view");
    Intent listIntent = new Intent(this, UserListActivity.class);
    list.setContent(listIntent);

    // Grid view
    TabSpec grid = tabHost.newTabSpec("Grid view");
    grid.setIndicator("Grid view");
    Intent gridIntent = new Intent(this, UserGridActivity.class);
    grid.setContent(gridIntent);

    // Update Info
    TabSpec update = tabHost.newTabSpec("Update Info");
    update.setIndicator("Update Info");
    Intent updateIntent = new Intent(this, UpdateInformationUser.class);
    update.setContent(updateIntent);

    // Authentication
    TabSpec auth = tabHost.newTabSpec("Unlock");
    auth.setIndicator("Unlock");
    Intent authIntent = new Intent(this, Authentication.class);
    auth.setContent(authIntent);

    // add all tabs
    tabHost.addTab(list);
    tabHost.addTab(grid);
    tabHost.addTab(update);
    tabHost.addTab(auth);

    //set Windows tab as default (zero based)
    tabHost.setCurrentTab(0);
}
}
Dave
  • 117
  • 11
  • You're probably better off running it with a timeout, rather than sleep mode. – durbnpoisn Feb 10 '16 at 14:03
  • what do you mean? example? – Dave Feb 10 '16 at 14:07
  • I'd recommend onStop followed by an onRestart. Yet in this case, when user presses the home button and open the app again, it will still go to the Login page, not only when phone sleeps. onStop-onRestart causes your app to go to the login page every time your app is closed, stopped. – Onur Çevik Feb 10 '16 at 14:20
  • Whatever you're planning on doing here, it seems like a terribly bad practice to me. I can't imagine why your app needs to be SO secure that it logs out the user every time they turn off their screen. – durbnpoisn Feb 10 '16 at 14:39
  • @OnurÇevik How can i implement onStop and onRestart into my app? Is there any example? – Dave Feb 10 '16 at 16:06
  • Just override them. Ctrl + O if you are using Android Studio – Onur Çevik Feb 12 '16 at 12:22

0 Answers0