开发者

Unpredictable behavior onStart() onPause() and onResume()

I have break points setup on the super's of onStart, onPause, and onResume in multiple activities. I want to handle the back button being pressed and instead of going back to the main activity I am trying to get my program to goto the last activity before the back button.

When playing around in debug mode and following these three functions calls I am finding that they are unpredictable. When a choice is made to advance to another activity the activity I was in has its onResume() called where I thought onPause() would be called and after onResume(), onStop() is called.

What am I doing wrong here?

  <application android:icon="@drawable/icon" android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
>
    <activity android:name=".SplashScreen"
              android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" android:configChanges="keyboardHidden|orientation"/>
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name=".MainActivity"
    android:label="@string/app_name" android:configChanges="keyboardHidden|orientation"/>
    <activity android:name=".CountrySelection"  android:label="@string/app_name" android:configChanges="keyboardHidden|orientation"/>
    <activity android:name=".StateSelecti开发者_如何转开发on"  android:label="@string/app_name" android:configChanges="keyboardHidden|orientation"/>
    <activity android:name=".CitySelection"  android:label="@string/app_name" android:configChanges="keyboardHidden|orientation"/>
    <activity android:name=".CategorySelection"  android:label="@string/app_name" android:configChanges="keyboardHidden|orientation"/>
    <activity android:name=".SubCategorySelection"  android:label="@string/app_name" android:configChanges="keyboardHidden|orientation"/>
    <activity android:name=".DisplayAdsActivity"  android:label="@string/app_name" android:configChanges="keyboardHidden|orientation"/>
    <activity android:name=".DisplayAdActivity"  android:label="@string/app_name" android:configChanges="keyboardHidden|orientation"/>
    <activity android:name=".SavedAdsActivity" android:label="@string/app_name" android:configChanges="keyboardHidden|orientation"/>

</application>

    case R.id.locationbutton:{

            Intent i = new Intent();
            i.putExtra("Locations",continents);
            i.setClass(this,CountrySelection.class);
            startActivityForResult(i,LOCATION_REQUEST_CODE);
            break;

        }

@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
    // TODO Auto-generated method stub
    //super.onListItemClick(l, v, position, id);
    Intent i = new Intent();
    location = position;
    i.putExtra("States",continents.get(position).getStates());
    i.setClass(this, StateSelection.class);
    startActivityForResult(i,0);


}

@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
    // TODO Auto-generated method stub
    //super.onListItemClick(l, v, position, id);
    Intent i = new Intent();
    i.putExtra("Cities",states.get(position).getCounties());
    i.setClass(this, CitySelection.class);
    startActivityForResult(i,0);

}


Have you looked at this which describes how to set flags on your Intent to define how they should (or should not) go on the stack?

By default, when you have a chain of activities being called, the last one should be shown when hitting the back key. Can you post some code to show us how your calling your other activities?


Basically, in your onActivityResult, you must check the actual result.

if (resultCode == RESULT_CANCELED) {
    // The user pressed back, don't do anything
} else {
    // the user did not pressed back, you can finish:
    setResult(RESULT_OK);
    finish();
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜