(我不是新手!,记忆就足够了。)
我正在研究android ICS(SDK 4.0),当我调用startActivityResult时,我的活动生命周期很奇怪。
之前的每次都会破坏!!
当另一个活动被召唤并且来到前方并重叠时,每次重叠活动 - 后面的活动 - 都会破坏,而不是在姜饼中看到(2.3.3)。
下面的日志只是Activity1调用Activity 2的程序,只是在Activity 2中按下后退键时返回结果.aigna没有任何标志。 这是我修改过的日志..
左边是在ICS(Gal Nex)中运行,右边是在Gingerbread(Nex one)中运行
Log when runned in GingerBread
-------
- Start ActivityStackTest1 and launched ActivityStackTest2 immediately.
_ActivityStackTest1 _ onCreate_called..
_ActivityStackTest1 _ onCreate_calling new activity.. - starting activity for result
_ActivityStackTest1 _ onStart_called..
_ActivityStackTest1 _ onResume_called..
_ActivityStackTest1 _ onSaveInstanceState_called..
_ActivityStackTest1 _ onPause_called..
_ActivityStackTest2 _ onCreate_rendering..
_ActivityStackTest2 _ onCreate_got str - PASSED INTENT STRING
_ActivityStackTest2 _ onStart_called..
_ActivityStackTest2 _ onResume_called..
_ActivityStackTest1 _ onStop_called..
- Pressed Back Key and returned to ActivityStackTest1.
_ActivityStackTest2 _ onPause_called..
_ActivityStackTest1 _ onActivityResult_returned somehow.
_ActivityStackTest1 _ onStart_called..
_ActivityStackTest1 _ onResume_called..
_ActivityStackTest2 _ onStop_called..
Log when runned in IcecreamSandwich
=======
- Start ActivityStackTest1 and launched ActivityStackTest2 immediately.
_ActivityStackTest1 _ onCreate_called..
_ActivityStackTest1 _ onCreate_calling new activity.. - starting activity for result
_ActivityStackTest1 _ onStart_called..
_ActivityStackTest1 _ onResume_called..
_ActivityStackTest1 _ onSaveInstanceState_called..
_ActivityStackTest1 _ onPause_called..
_ActivityStackTest2 _ onCreate_rendering..
_ActivityStackTest2 _ onCreate_got str - PASSED INTENT STRING
_ActivityStackTest2 _ onStart_called..
_ActivityStackTest2 _ onResume_called..
_ActivityStackTest1 _ onStop_called..
**_ActivityStackTest1 _ onDestroy_called..** <- ???
- Pressed Back Key and returned to ActivityStackTest1.
_ActivityStackTest2 _ onPause_called..
_ActivityStackTest1 _ onCreate_called..
_ActivityStackTest1 _ onCreate_calling new activity.. - starting activity for result
_ActivityStackTest1 _ onStart_called..
_ActivityStackTest1 _ onActivityResult_returned somehow.
_ActivityStackTest1 _ onResume_called..
_ActivityStackTest1 _ onSaveInstanceState_called..
_ActivityStackTest1 _ onPause_called..
_ActivityStackTest1 _ onStop_called..
_ActivityStackTest1 _ onDestroy_called..
我在想错吗?是不是之前的活动应该等到孩子活动结束,而不是自己完成?
是否有任何问题改变了ICS后的生命周期? 当你对它有所了解时,请注意我,这非常令人头疼。
添加 - 我的代码在这里......如果需要的话。
ACT1 包kr.bos.Subclasses;
import kr.bos.Framework.BaseActivity;
import kr.bos.Framework.Logger;
import android.content.Intent;
import android.content.res.Configuration;
import android.os.Bundle;
public class ActivityStackTest1 extends BaseActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Logger.e("called..");
if(!mOptionA) {
Logger.i("calling new activity.. - starting activity for result");
Intent intent = new Intent(this,ActivityStackTest2.class);
intent.putExtra("STRING", "PASSED INTENT STRING");
startActivityForResult(intent , 0);
}
}
@Override protected void onStart() {
// FIXME Auto-generated method stub
super.onStart();
Logger.e("called..");
}
@Override protected void onResume() {
// FIXME Auto-generated method stub
super.onResume();
Logger.e("called..");
}
@Override protected void onPause() {
super.onPause();
Logger.e("called..");
}
@Override protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
Logger.e("called..");
}
@Override protected void onStop() {
// FIXME Auto-generated method stub
super.onStop();
Logger.e("called..");
}
@Override protected void onDestroy() {
// FIXME Auto-generated method stub
super.onDestroy();
Logger.e("called..");
}
@Override
protected void onActivityResult(int requestCode, int resultCode,
Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Logger.i("returned somehow.");
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
Logger.i("on configuration change");
}
}
ACT2 包kr.bos.Subclasses;
import kr.bos.Framework.BaseActivity;
import kr.bos.Framework.Logger;
import android.content.res.Configuration;
import android.os.Bundle;
public class ActivityStackTest2 extends BaseActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Logger.i("rendering..");
String strget = getIntent().getStringExtra("STRING");
Logger.i("got str - "+strget);
}
@Override protected void onStart() {
// FIXME Auto-generated method stub
super.onStart();
Logger.e("called..");
}
@Override protected void onResume() {
// FIXME Auto-generated method stub
super.onResume();
Logger.e("called..");
}
@Override protected void onPause() {
super.onPause();
Logger.e("called..");
}
@Override protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
Logger.e("called..");
}
@Override protected void onStop() {
// FIXME Auto-generated method stub
super.onStop();
Logger.e("called..");
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
Logger.i("on configuration change");
}
@Override
public void onBackPressed() {
setResult(0);
super.onBackPressed();
}
}
答案 0 :(得分:5)
解决。确保“选项 - 开发 - 不要保持活动”未经检查。 除非,你所做的所有活动都会让人感到奇怪。
检查相关问题 http://androidforums.com/verizon-galaxy-nexus/482038-dont-keep-activities-box.html http://forum.xda-developers.com/showthread.php?t=1365748
答案 1 :(得分:2)
没有人说这不会发生。 onActivityResult()
是唯一的承诺!