Why doesn't setting clearTaskOnLaunch=“true” cause OnCreate to be called?

来源:互联网 发布:数据的作用的是什么 编辑:程序博客网 时间:2024/05/16 07:27
0 down vote favorite

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

link|flag





2 Answers

activenewestvotes
up vote 1 down vote

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.

link|flag


Are you saying that clearTaskOnLaunch="true" does not start the application as if it were are "fresh" launch? – user274610 Apr 5 at 19:58

Yes I believe so. (I'm new to android, so please don't assume that this is the definitive answer) – Sid NoParrots Apr 6 at 9:35

original from:
http://stackoverflow.com/questions/2580009/why-doesnt-setting-cleartaskonlaunchtrue-cause-oncreate-to-be-called

android:clearTaskOnLaunch="true"

这个参数意思是无论何时这个activity都会从home screen重新启动,也就是只要你按了桌面的图标,这个活动就是第一个发起的。但是唯一要注意的是如果你按下的是home建 那么意味着这个活动没有结束,所以你在按有时候就不会第一次发起了。只有当你按下back或者结束当前执行的任务之类代表能使activity结束的行为 这个活动都会第一次发起。

up vote 0 down vote

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.

link|flag