2009-09-15 92 views
4

假设有三个活动,显示顺序是a-> b-> c。 现在,我想直接继续活动一,在Activity c完成一些操作后。 直接通过Activity c恢复Activity a,但创建Activity a的新实例。如何恢复活动?

+0

为什么你想要一个新的Activity a实例经过a-> b-> c-> a – 2009-09-16 07:57:12

+4

什么,你想恢复还是重新启动?你可以通过发送带有标志ACTIVITY_CLEAR_TOP的Intent来恢复它,或者你完成旧的并重新启动它(然后你得到一个新的实例)。 – Matthias 2009-09-16 12:05:49

回答

2

as @Matthias表示,你想恢复还是重新启动Activity a?如果你想重新启动它,那么你会包括FLAG_ACTIVITY_CLEAR_TASK在你的意图这是这样的:"If set in an Intent passed to Context.startActivity(), this flag will cause any existing task that would be associated with the activity to be cleared before the activity is started"

,或者你很可能只是调用finish();活动的

,如果你想恢复它,那么你只需要调用startActivity(new Intent(Parent.this, ActivityA.class));或任何你的代码是

其他信息:ActivitiesIntentActivity and Task Design

2
  • 在b中您可以使用的onResume()方法,内容为finish() as:

BroadcastReceiver receiverFinish = null;

@Override 

protected void onResume() { 

    super.onResume(); 
    if(receiverFinish!=null){ 
     unregisterReceiver(receiverFinish); 
    } 
    receiverFinish=new BroadcastReceiver() { 
@Override   
public void onReceive(Context context, Intent intent) { 


       if(intent.getAction().equals("finish.activity")){ 
         MyActivity.this.finish(); 
        } 
           }  }; 
       registerReceiver(receiverFinish, new IntentFilter("finish.activity")); 

    } 
  • 然后在C调用:

//完成B活性

意向意图=新意图( “finish.activity”); sendBroadcast(intent);

//完成c活动

finish();

  • 希望对你有用!好咕噜!
  • Pham Trung Phuong - Vsoft Corp
+0

因此,可以在onPause()被调用后让一个接收方注册吗? – 2013-10-08 20:20:59