简体   繁体   English

Android:如何在BroadCast Receiver中检查一次活动是否已完成

[英]Android: how to check in BroadCast Receiver that activity has been completed once

I have 3 activities which a BroadCast Receiver start. 我有3个BroadCast接收器开始的活动。 I want to check in BroadCast Receiver the 3 activities that which one was the last one finished and the second finished and then run the third activity. 我想检查BroadCast Receiver的3个活动,其中最后一个完成,第二个完成,然后运行第三个活动。 And do check all the time before starting an activity. 并在开始活动前检查所有时间。 Please help me how to resolve this issue. 请帮助我如何解决此问题。

You can do it using SharedPreferences . 您可以使用SharedPreferences做到这一点。 When an activity is about to finish, write this event in the SharedPreferences . 活动即将结束时,将此事件写入SharedPreferences In the BroadcastReceiver , check this event. BroadcastReceiver ,检查此事件。

PS: Let me know if you need more details on how to use it. PS:如果您需要更多有关如何使用它的详细信息,请告诉我。

Make one satic counter for increment

Static int counter_Activity=0; 静态int counter_Activity = 0;

Do for all Three Activity

counter_Activity++;
finish();
pref = _context.getSharedPreferences(PREF_NAME, PRIVATE_MODE);
editor = pref.edit();
editor.putString(counter_Activity,Activity_name);
editor.commit();


For Checking in Brodcast Class.

pref = _context.getSharedPreferences(PREF_NAME, PRIVATE_MODE);
pref.getInt(1,Activity_name-1); 
pref.getInt(2,Activity_name-2); 
pref.getInt(3,Activity_name-3); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM