Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is onResume() called when an activity starts?

I have an app where after sign in it throws you at the welcome screen. I put a Toast to see when the onResume fires, but it also fires after onCreate

protected void onResume(){
    super.onResume();
    Database openHelper = new Database(this);//create new Database to take advantage of the SQLiteOpenHelper class
    myDB2 = openHelper.getReadableDatabase(); // or getWritableDatabase();
    myDB2=SQLiteDatabase.openDatabase("data/data/com.example.login2/databases/aeglea", null, SQLiteDatabase.OPEN_READONLY);//set myDB to aeglea
         cur = fetchOption("SELECT * FROM user_login");//use above to execute SQL query
         msg.setText("Username: "+cur.getString(cur.getColumnIndex("username"))
                     +"\nFull name: "+cur.getString(cur.getColumnIndex("name"))+" "+cur.getString(cur.getColumnIndex("last"))
                     +"\ne-mail: "+cur.getString(cur.getColumnIndex("email"))
                     +"\nAeglea id:"+cur.getString(cur.getColumnIndex("uid")));

         Toast.makeText(getApplicationContext(), "RESUMED", Toast.LENGTH_SHORT).show();
}

It comes from:

 //create new intent
 Intent log = new Intent(getApplicationContext(), Welcome.class);
 // Close all views before launching logged
  log.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
  startActivity(log);
   // Close Login Screen
   finish();

I am baffled. Please offer some experience here

like image 400
MayTheSchwartzBeWithYou Avatar asked Aug 30 '12 18:08

MayTheSchwartzBeWithYou


Video Answer


1 Answers

Well i do not understand very well what you are trying to ask or what is the question here. BUT i will recommend you to read the "Android Activity LifeCycle" and that will clear many of your doubts cause in android is not the same as other languages or platforms.

enter image description here

Note: The OnResume is call each time the activity is "visible", so as many times as your activity becomes visible, the same number of times your method will be called. If you just want to call the method the first time, then the OnCreate is what your looking for.

like image 180
Jorge Aguilar Avatar answered Nov 15 '22 22:11

Jorge Aguilar