Question

I got two activities.....LoginActivity(Launcher Activity) and MainActivity. When the app is installed and started the LoginActivity is invoked and on entering the username and password, it authenticate from a server and starts the MainActivity. This works fine.

when the app is minimized or Paused using backbutton or homebutton and resumed again i want the app to resume from the MainActivity. How can that be done...I am a beginner...please help!!Thanks.

Was it helpful?

Solution 2

You have to set Global boolean variable and set it to true when you successfully login and check it on resume activity of LoginActivity and start an Intent of MainActivity. Here is the code..

boolean mainActi = false;
mainActi = true;

@Override
protected void onResume() {

super.onResume();

f(mainActi) {
     Intent i1  = new Intent(MainActivity.this,LogIn.class);
     startActivity(i1);
     mainActi = false;
   }
 }

OTHER TIPS

By finishing() your LoginActivity(Launcher Activity) , and storing your data ( LoginActivity ) in Bundle argument in Bundle .... and restoring that data in onResume() of MainActivity with the help of Bundle of argument .

Edited :

Create a global_Bundle_Argument LoginActivity .

Bundle bun ;

and , inside onCreate put this.bun = bun ; bun.putString(key, value) ;

send this bundle argument with intent : intent.putExtra(name, value) ;

and get this bundle argument in MainActivity() ; Bundle bun = intent.getBundleExtra(name) .

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top