为什么在活动开始时调用onResume()? [英] Why is onResume() called when an activity starts?

查看:76
本文介绍了为什么在活动开始时调用onResume()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,登录后将您带到欢迎屏幕.我举杯祝愿onResume何时触发,但onCreate之后也会触发

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();
}

它来自:

 //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

推荐答案

好吧,我不太了解您要问的问题或这里的问题是什么.但是,我建议您阅读" Android Activity LifeCycle ",这将清除您在android中与其他语言或平台不一样的许多疑问.

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.

注意:每次活动可见"时都会调用OnResume,因此,只要活动可见,就会调用方法的次数相同.如果您只是想第一次调用该方法,那么OnCreate就是您想要的.

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.

这篇关于为什么在活动开始时调用onResume()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆