tags:

views:

169

answers:

2

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

+1  A: 

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.

Sid NoParrots
Are you saying that clearTaskOnLaunch="true" does not start the application as if it were are "fresh" launch?
Yes I believe so. (I'm new to android, so please don't assume that this is the definitive answer)
Sid NoParrots
A: 

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.

rascalking