从主要活动中,我调用带有警报管理器的广播接收器来启动重复功能。我还创建了共享时段的偏好。如何将周期时间整数传递给另一个类广播接收器?
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
SharedPreferences preferences = getSharedPreferences("dataiowebusb" , VATE);
String strUpdatetime = preferences.getString("Period","3");
text5.setText(strUpdatetime);
Tperiod =Integer.parseInt(strUpdatetime);
if(Tperiod>1200){
Tperiod=1200;//20min
}
sendBroadcast(new Intent(this,MyScheduleReceiver.class));//Call ala
}
public class MyScheduleReceiver extends BroadcastReceiver {
public static int period=20;
private static final long REPEAT_TIME = 1000 * period;
public void onReceive(Context context, Intent intent) {
AlarmManager service = (AlarmManager) context
.getSystemService(Context.ALARM_SERVICE);
Intent i = new Intent(context, MyStartServiceReceiver.class);
如果我在广播接收器类中使用共享首选项,则会出现错误 MODE_PRIVATE..