如何将数据传递到先于previous活动活动 [英] How to pass data to the activity that is prior to the previous activity
问题描述
我有三个活动,如: A,B和C. A启动B,和B开始C.我将从C.后面堆栈中删除B,那么我需要从C一些数据传递到之前,我完成C.我的问题是如何通过从数据C到A?
I have three activity, eg. A, B and C. A start B, and B start C. I will remove B from the back stack in C. Then I need to pass some data from C to A before I finish C. My question is how to pass data from C to A ?
推荐答案
如果你想完成C的活性,那么你可以使用广播接收器在一个活动之前,从C的一些数据传递给可以从C发送广播到A直接。
If you want to pass some data from C to A before finishing C activity then you can use broadcast receiver in your A activity and can send broadcast from C to A directly.
写下面的code。
BroadcastReceiver brd_receiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals("receive data from C")) {
// DO YOUR WORK HERE.
}
}
};
registerReceiver(brd_receiver, new IntentFilter("receive data from C"));
写这篇code,从活动的C数据发送到活性的。
Write this code to send data from activity C to activity A.
Intent intent = new Intent();
intent.setAction("receive data from C");
intent.putExtra(name, value); //SAVE YOU DATA INTO INTENT.
sendBroadcast(intent);
希望它会帮助你,如果它不能正常工作,然后告诉我,你所面对的问题。我认为它应该工作。
Hope it will help you if it is not working then tell me the problem you are facing. I think it should work.
这篇关于如何将数据传递到先于previous活动活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!