Why doesn't setting clearTaskOnLaunch=“true” cause OnCreate to be called?
来源:互联网 发布:数据的作用的是什么 编辑:程序博客网 时间:2024/05/16 07:27
My application works fine, once it is initialized in the OnCreate method of my View class. However, when I open my app after the Droid phone has been sitting idle all night, the OnCreate method is not being called.
I use the OnCreate to initialize data, and that in turn initializes the GUI. The GUI clearly shows that OnCreate was not called.
I tried setting clearTaskOnLaunch="true" in my Manifest. My Manifest is:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.hedgetools.trin"
android:versionCode="2"
android:versionName="1.02">
<application android:icon="@drawable/icon"
android:label="@string/app_name"
android:clearTaskOnLaunch="true">
<activity android:name=".Trin"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
/application>
<uses-sdk android:minSdkVersion="6"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
</manifest>
This did not help. My OnCreate method is not being call after the Droid phone sits idle all night.
Why doesn’t clearTaskOnLaunch cause OnCreate to be called?Any help or suggestions will be greatly appreciated.
Charles
2 Answers
OnCreate gets called only when the application is launched as a fresh one. Subsequently the OnResume function gets called.
See http://developer.android.com/reference/android/app/Activity.html for a description of the application life cycle.
http://stackoverflow.com/questions/2580009/why-doesnt-setting-cleartaskonlaunchtrue-cause-oncreate-to-be-called
android:clearTaskOnLaunch="true"
这个参数意思是无论何时这个activity都会从home screen重新启动,也就是只要你按了桌面的图标,这个活动就是第一个发起的。但是唯一要注意的是如果你按下的是home建 那么意味着这个活动没有结束,所以你在按有时候就不会第一次发起了。只有当你按下back或者结束当前执行的任务之类代表能使activity结束的行为 这个活动都会第一次发起。
clearTaskOnLaunch tells android to remove any activities other than the main one from the history stack when you launch it from home. it has nothing to do with triggering onCreate.
Sidharth has it right, for that you need to put your initialization in onResume, not onCreate. see the diagram in http://developer.android.com/reference/android/app/Activity.html#ActivityLifecycle for a very quick explanation of the different activity states.
- Why doesn't setting clearTaskOnLaunch=“true” cause OnCreate to be called?
- android:clearTaskOnLaunch="true"
- Why dynamic_cast doesn't work ?
- Add rightBarButtonItem but doesn't seem to be working
- 使用Slidingmenu爆出“Both setBehindContentView must be called in onCreate in addition to setContentView.”
- android:clearTaskOnLaunch=true 和android:finishTaskOnLaunch=true
- android:clearTaskOnLaunch=true 和android:finishTaskOnLaunch=true区别
- Fragment's onOptionsItemSelected doesn't get called
- Why doesn't Linux need defragmenting?
- Why doesn't Linux need defragmenting?
- Why doesn't my new Favicon display?
- Why doesn't C++ provide heterogenous containers?
- ROOT: Why TStyle::SetStatFontSize() doesn't work?
- Why doesn't .bashrc run automatically?
- Why NIO doesn't use Stream
- Why Doesn't Python Have Switch/Case?
- why vue.js doesn't support templateURL
- Can't convert boolean to string automatically, because the "boolean_format" setting was "true,false"
- shell关于文件的判断
- Asterisk 1.2.x至1.6.x版本更新分析 (Part of IP PBX产品化预研分析)(转)
- Windows 7 IIS (HTTP Error 500.21 - Internal Server Error)解决
- SQL安全相关
- 质量意识
- Why doesn't setting clearTaskOnLaunch=“true” cause OnCreate to be called?
- 线程
- log4j配置(总结)下
- LOGMNR使用
- 从开发到测试
- JavaEE配置文件application.xml介绍
- 怎么去掉Flex4生成的SWF加载时的进度条
- 关于Lable的设置
- 使用dbms_repair修复坏块