不是单例模式,你用不了
It is not under singleton mode, U can't use it
在我的提醒应用程序中,如果我 select 时间刚刚过去,则应用程序无法运行,出现以下错误:
日志
D/ANRAppManager: !!! It is not under singleton mode, U can't use it. !!!
05-13 10:55:19.934 22594-22600/com.mri I/dalvikvm: threadid=3: reacting to signal 3
05-13 10:55:20.190 22594-22600/com.mri D/dalvikvm: JIT unchain all for threadid=1
05-13 10:55:20.940 22594-22600/com.mri W/dalvikvm: threadid=3: spin on suspend #1 threadid=1 (pcf=0)
05-13 10:55:20.940 22594-22600/com.mri E/dalvikvm: Fatal spin-on-suspend, dumping threads
05-13 10:55:20.940 22594-22600/com.mri I/dalvikvm: DALVIK THREADS:
05-13 10:55:20.940 22594-22600/com.mri I/dalvikvm: (mutexes: tll=1 tsl=1 tscl=0 ghl=0)
05-13 10:55:20.940 22594-22600/com.mri I/dalvikvm: "main" prio=5 tid=1 RUNNABLE JIT
05-13 10:55:20.940 22594-22600/com.mri I/dalvikvm: | group="main" sCount=1 dsCount=0 obj=0x4191cde0 self=0x418328b8
05-13 10:55:20.940 22594-22600/com.mri I/dalvikvm: | sysTid=22594 nice=0 sched=0/0 cgrp=apps handle=1074880900
05-13 10:55:20.941 22594-22600/com.mri I/dalvikvm: | state=R schedstat=( 133450832707 8412096123 56516 ) utm=13019 stm=326 core=0
05-13 10:55:20.941 22594-22600/com.mri I/dalvikvm: at com.mri.reminders.AlarmReceiver.setRepeatAlarm(AlarmReceiver.java:~115)
05-13 10:55:20.941 22594-22600/com.mri I/dalvikvm: at com.mri.reminders.ReminderAddActivity.saveReminder(ReminderAddActivity.java:963)
05-13 10:55:20.941 22594-22600/com.mri I/dalvikvm: at com.mri.reminders.ReminderAddActivity.onOptionsItemSelected(ReminderAddActivity.java:1172)
05-13 10:55:20.942 22594-22600/com.mri I/dalvikvm: at android.app.Activity.onMenuItemSelected(Activity.java:2633)
05-13 10:55:20.945 22594-22600/com.mri I/dalvikvm: at android.support.v4.app.FragmentActivity.onMenuItemSelected(FragmentActivity.java:361)
05-13 10:55:20.945 22594-22600/com.mri I/dalvikvm: at android.support.v7.app.AppCompatActivity.onMenuItemSelected(AppCompatActivity.java:147)
05-13 10:55:20.945 22594-22600/com.mri I/dalvikvm: at android.support.v7.view.WindowCallbackWrapper.onMenuItemSelected(WindowCallbackWrapper.java:100)
这是我在 AlarmReceiver.java
中使用的代码
public void setRepeatAlarm(Context context, Calendar calendar, int ID, long RepeatTime) {
mAlarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
// Put Reminder ID in Intent Extra
Intent intent = new Intent(context, AlarmReceiver.class);
intent.putExtra(ReminderEditActivity.EXTRA_REMINDER_ID, Integer.toString(ID));
mPendingIntent = PendingIntent.getBroadcast(context, ID, intent, PendingIntent.FLAG_CANCEL_CURRENT);
// Calculate notification timein
Calendar c = Calendar.getInstance();
long currentTime = c.getTimeInMillis();
long diffTime = calendar.getTimeInMillis() - currentTime;
while(diffTime < 0) {
diffTime += RepeatTime; // at this line getting error
}
// Start alarm using initial notification time and repeat interval time
mAlarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME,
SystemClock.elapsedRealtime() + diffTime,
RepeatTime , mPendingIntent);
// Restart alarm if device is rebooted
ComponentName receiver = new ComponentName(context, BootReceiver.class);
PackageManager pm = context.getPackageManager();
pm.setComponentEnabledSetting(receiver,
PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
PackageManager.DONT_KILL_APP);
}
我该如何解决这个问题?
我认为 对信号 3 做出反应 是 ANR 的症状。应用程序在崩溃前是否挂起?如果是这样,可能是因为循环永远不会结束。
您确定 RepeatTime
总是 > 0(特别是不是 = 0)吗?
类似于:
while(diffTime < 0) {
Log.d("SOME_TAG", "set diffTime to " + diffTime);
diffTime += RepeatTime; // at this line getting error
}
不应显示多于几行。
更新:
您应该确保闹钟在未来或重复时间大于0。
if (diffTime > 0 || RepeatTime > 0) {
// set the alarm only if the parameters are consistents
while(diffTime < 0) {
diffTime += RepeatTime; // at this line getting error
}
// Start alarm using initial notification time and repeat interval time
mAlarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME,
SystemClock.elapsedRealtime() + diffTime,
RepeatTime , mPendingIntent);
// Restart alarm if device is rebooted
ComponentName receiver = new ComponentName(context, BootReceiver.class);
PackageManager pm = context.getPackageManager();
pm.setComponentEnabledSetting(receiver,
PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
PackageManager.DONT_KILL_APP);
}
在我的提醒应用程序中,如果我 select 时间刚刚过去,则应用程序无法运行,出现以下错误:
日志
D/ANRAppManager: !!! It is not under singleton mode, U can't use it. !!!
05-13 10:55:19.934 22594-22600/com.mri I/dalvikvm: threadid=3: reacting to signal 3
05-13 10:55:20.190 22594-22600/com.mri D/dalvikvm: JIT unchain all for threadid=1
05-13 10:55:20.940 22594-22600/com.mri W/dalvikvm: threadid=3: spin on suspend #1 threadid=1 (pcf=0)
05-13 10:55:20.940 22594-22600/com.mri E/dalvikvm: Fatal spin-on-suspend, dumping threads
05-13 10:55:20.940 22594-22600/com.mri I/dalvikvm: DALVIK THREADS:
05-13 10:55:20.940 22594-22600/com.mri I/dalvikvm: (mutexes: tll=1 tsl=1 tscl=0 ghl=0)
05-13 10:55:20.940 22594-22600/com.mri I/dalvikvm: "main" prio=5 tid=1 RUNNABLE JIT
05-13 10:55:20.940 22594-22600/com.mri I/dalvikvm: | group="main" sCount=1 dsCount=0 obj=0x4191cde0 self=0x418328b8
05-13 10:55:20.940 22594-22600/com.mri I/dalvikvm: | sysTid=22594 nice=0 sched=0/0 cgrp=apps handle=1074880900
05-13 10:55:20.941 22594-22600/com.mri I/dalvikvm: | state=R schedstat=( 133450832707 8412096123 56516 ) utm=13019 stm=326 core=0
05-13 10:55:20.941 22594-22600/com.mri I/dalvikvm: at com.mri.reminders.AlarmReceiver.setRepeatAlarm(AlarmReceiver.java:~115)
05-13 10:55:20.941 22594-22600/com.mri I/dalvikvm: at com.mri.reminders.ReminderAddActivity.saveReminder(ReminderAddActivity.java:963)
05-13 10:55:20.941 22594-22600/com.mri I/dalvikvm: at com.mri.reminders.ReminderAddActivity.onOptionsItemSelected(ReminderAddActivity.java:1172)
05-13 10:55:20.942 22594-22600/com.mri I/dalvikvm: at android.app.Activity.onMenuItemSelected(Activity.java:2633)
05-13 10:55:20.945 22594-22600/com.mri I/dalvikvm: at android.support.v4.app.FragmentActivity.onMenuItemSelected(FragmentActivity.java:361)
05-13 10:55:20.945 22594-22600/com.mri I/dalvikvm: at android.support.v7.app.AppCompatActivity.onMenuItemSelected(AppCompatActivity.java:147)
05-13 10:55:20.945 22594-22600/com.mri I/dalvikvm: at android.support.v7.view.WindowCallbackWrapper.onMenuItemSelected(WindowCallbackWrapper.java:100)
这是我在 AlarmReceiver.java
中使用的代码public void setRepeatAlarm(Context context, Calendar calendar, int ID, long RepeatTime) {
mAlarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
// Put Reminder ID in Intent Extra
Intent intent = new Intent(context, AlarmReceiver.class);
intent.putExtra(ReminderEditActivity.EXTRA_REMINDER_ID, Integer.toString(ID));
mPendingIntent = PendingIntent.getBroadcast(context, ID, intent, PendingIntent.FLAG_CANCEL_CURRENT);
// Calculate notification timein
Calendar c = Calendar.getInstance();
long currentTime = c.getTimeInMillis();
long diffTime = calendar.getTimeInMillis() - currentTime;
while(diffTime < 0) {
diffTime += RepeatTime; // at this line getting error
}
// Start alarm using initial notification time and repeat interval time
mAlarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME,
SystemClock.elapsedRealtime() + diffTime,
RepeatTime , mPendingIntent);
// Restart alarm if device is rebooted
ComponentName receiver = new ComponentName(context, BootReceiver.class);
PackageManager pm = context.getPackageManager();
pm.setComponentEnabledSetting(receiver,
PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
PackageManager.DONT_KILL_APP);
}
我该如何解决这个问题?
我认为 对信号 3 做出反应 是 ANR 的症状。应用程序在崩溃前是否挂起?如果是这样,可能是因为循环永远不会结束。
您确定 RepeatTime
总是 > 0(特别是不是 = 0)吗?
类似于:
while(diffTime < 0) {
Log.d("SOME_TAG", "set diffTime to " + diffTime);
diffTime += RepeatTime; // at this line getting error
}
不应显示多于几行。
更新:
您应该确保闹钟在未来或重复时间大于0。
if (diffTime > 0 || RepeatTime > 0) {
// set the alarm only if the parameters are consistents
while(diffTime < 0) {
diffTime += RepeatTime; // at this line getting error
}
// Start alarm using initial notification time and repeat interval time
mAlarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME,
SystemClock.elapsedRealtime() + diffTime,
RepeatTime , mPendingIntent);
// Restart alarm if device is rebooted
ComponentName receiver = new ComponentName(context, BootReceiver.class);
PackageManager pm = context.getPackageManager();
pm.setComponentEnabledSetting(receiver,
PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
PackageManager.DONT_KILL_APP);
}