我在onStart,onPause和onResume的super上设置了断点 活动。我想处理按下的后退按钮,而不是回到主要活动,我试图让我的程序转到后退按钮之前的最后一个活动。
在调试模式下玩游戏并跟随这三个函数调用时,我发现它们是不可预测的。当选择进入另一个活动时,我所在的活动的onResume()被调用,我认为onPause()将被调用,而在onResume()之后,调用onStop()。
我在这里做错了什么?
<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=".StateSelection" 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);
}
答案 0 :(得分:1)
您是否看过this,其中介绍了如何在Intent上设置标志以定义它们应该(或不应该)进入堆栈的方式?
默认情况下,当您调用一系列活动时,应该在按下后退键时显示最后一个。您是否可以发布一些代码向我们展示您如何调用其他活动?
答案 1 :(得分:1)
基本上,在onActivityResult中,您必须检查实际结果。
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();
}