Android:单击后退按钮时不调用OnCreate()方法

Android:单击后退按钮时不调用OnCreate()方法,第1张

概述我面临一个非常奇怪的问题.在我的活动中,当我按下Back按钮时,它不调用父活动的onCreate()方法. 这是我的代码:                   公共类AddNewGrocery扩展Activity { private DBHelper mydb ; Button btnSave; EditText editName; EditText editQty; EditText e 我面临一个非常奇怪的问题.在我的活动中,当我按下Back按钮时,它不调用父活动的onCreate()方法.

这是我的代码:
                  公共类AddNewGrocery扩展Activity {

private DBHelper mydb ; button btnSave; EditText editname; EditText editQty; EditText editPrice;@OverrIDeprotected voID onCreate(Bundle savedInstanceState) {    super.onCreate(savedInstanceState);    getActionbar().setdisplayHomeAsUpEnabled(true);    getActionbar().setTitle("Add List Item Details");    /** Setting a custom layout for the List activity */    setContentVIEw(R.layout.add_grocery);     btnSave = (button) findVIEwByID(R.ID.btnSave);    editname = (EditText) findVIEwByID(R.ID.txtname);    editQty=(EditText) findVIEwByID(R.ID.txtqty);    editPrice=(EditText) findVIEwByID(R.ID.txtPrice);    mydb = new DBHelper(this);

}}

这是我的mainfeast文件的代码:

<activity        androID:name="com.example.groceryList.MainActivity"        androID:label="@string/app_name" >        <intent-filter>            <action androID:name="androID.intent.action.MAIN" />            <category androID:name="androID.intent.category.LAUNCHER" />        </intent-filter>    </activity>     <activity        androID:name="com.example.groceryList.AddNewList"        androID:label="@string/app_name"       androID:parentActivityname="com.example.groceryList.MainActivity">     </activity>     <activity        androID:name="com.example.groceryList.AddNewGrocery"        androID:label="@string/app_name"         androID:parentActivityname="com.example.groceryList.AddNewList">     </activity>
解决方法 这是因为已经创建了父活动,但在访问另一个活动时它已暂停.如果要在返回活动时执行某些任务,可以使用“onResume()”方法.

见文件:Activity lifecycle

总结

以上是内存溢出为你收集整理的Android:单击后退按钮时不调用OnCreate()方法全部内容,希望文章能够帮你解决Android:单击后退按钮时不调用OnCreate()方法所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1127668.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-30
下一篇 2022-05-30

发表评论

登录后才能评论

评论列表(0条)

保存