Alarm Manager: cache Cleaner stops App

2019-07-20 19:18发布

问题:

i am making a simple alarm app and i want to show an activity after the given time has passed. here is the code i am trying.

  public void onReceive(Context c, Intent i) {
            Log.v("XXXX", S);
              Toast.makeText(c,  S+" minute(s) passed", Toast.LENGTH_LONG).show();

              Intent myIntent = new Intent(Main.this, AlarmBuzzer.class);
              myIntent.putExtra("ActivityName", activity_name);
              myIntent.putExtra("ActivityTime", S); //Optional parameters
              Main.this.startActivity(myIntent);
              }

       };

here if application is closed, the system showa toast but no BuzzerActivity is not shown. And if run cache cleaner neither toast nor Activity is shown. I want my app to run alarm manger even closed and show BuzzerActivity as a popUp when given time passes,

By the way i am using OneClean App to clean device memory.

Code for Setting Alarm

public void onClick(View v) {
     EditText et = (EditText) findViewById(R.id.editText1);
     EditText Activity_Name = (EditText) findViewById(R.id.editText2);
     activity_name = Activity_Name.getText().toString();
     S = et.getText().toString();
     long USER_TIME = Long.parseLong(S);
     TOTAL_TIME= (ONE_MINUTE*USER_TIME);
   //  DbConn();


     am.set( AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + 
TOTAL_TIME, pi );

}

LOG:

12-30 10:53:31.879: V/AlarmManager(232): set: Alarm{41b1a008 type 2 com.android.phone}
12-30 10:53:31.879: V/AlarmManager(232): Adding alarm Alarm{41b1a008 type 2 com.android.phone} at 1
12-30 10:53:31.879: V/AlarmManager(232): alarms: 15 type: 2
12-30 10:53:31.880: V/AlarmManager(232): 0: Jan 02 08:14:00 pm com.example.alarmmanager
12-30 10:53:31.880: V/AlarmManager(232): 1: Jan 02 08:14:11 pm com.android.phone
12-30 10:53:31.880: V/AlarmManager(232): 2: Jan 02 08:15:00 pm android
12-30 10:53:31.880: V/AlarmManager(232): 3: Jan 02 08:30:00 pm com.google.android.apps.maps
12-30 10:53:31.880: V/AlarmManager(232): 4: Jan 02 08:30:00 pm com.google.android.talk
12-30 10:53:31.880: V/AlarmManager(232): 5: Jan 02 08:30:00 pm com.google.android.talk
12-30 10:53:31.881: V/AlarmManager(232): 6: Jan 02 10:00:00 pm com.facebook.katana
12-30 10:53:31.881: V/AlarmManager(232): 7: Jan 02 11:15:00 pm com.google.android.talk
12-30 10:53:31.881: V/AlarmManager(232): 8: Jan 03 12:30:00 am com.google.android.talk
12-30 10:53:31.881: V/AlarmManager(232): 9: Jan 03 01:45:00 am com.google.android.talk
12-30 10:53:31.881: V/AlarmManager(232): 10: Jan 03 03:00:00 am com.google.android.talk
12-30 10:53:31.881: V/AlarmManager(232): 11: Jan 04 07:45:00 am com.google.android.talk
12-30 10:53:31.882: V/AlarmManager(232): 12: Jan 23 11:01:37 pm com.google.android.gms
12-30 10:53:31.882: V/AlarmManager(232): 13: Jan 23 11:01:37 pm com.google.android.gms
12-30 10:53:31.882: V/AlarmManager(232): 14: Jan 23 11:01:37 pm com.google.android.gms
12-30 10:53:31.961: I/SurfaceFlinger(95): [SurfaceFlinger] frames:2, duration:1.002000, fps:1.994219
12-30 10:53:32.245: D/Settings/Provide(232): lookupValue, table secure cache.containsKey sys_free_storage_log_interval
12-30 10:53:32.245: D/Settings/Provide(232): lookupValue, table secure cache.fullyMatchesDisk() sys_free_storage_log_interval
12-30 10:53:32.245: D/Settings/Provide(232): lookupValue, table secure cache.containsKey disk_free_change_reporting_threshold
12-30 10:53:32.245: D/Settings/Provide(232): lookupValue, table secure cache.fullyMatchesDisk() disk_free_change_reporting_threshold
12-30 10:53:59.935: I/InputDispatcher(232): wait for the command to run!
12-30 10:53:59.935: D/InputManager-JNI(232): pokeUserActivity : eventType=1
12-30 10:53:59.935: D/WindowManager(232): interceptKeyTi keyCode=3 down=false repeatCount=0 keyguardOn=false mHomePressed=true canceled=false
12-30 10:53:59.936: V/ActivityManager(232): Broadcast: Intent { act=android.intent.action.CLOSE_SYSTEM_DIALOGS flg=0x40000010 (has extras) } ordered=false
12-30 10:53:59.937: I/ActivityManager(232): START {act=android.intent.action.MAIN cat=[android.intent.category.HOME] flg=0x10200000 cmp=com.gionee.launcher/.GNLauncherActivity} from pid 232
12-30 10:53:59.938: V/ActivityManager(232): At 5 ckp TaskRecord{41443498 #119 A com.example.alarmmanager}: ActivityRecord{41b82248 com.example.alarmmanager/.Main}
12-30 10:53:59.938: V/ActivityManager(232): At 4 ckp TaskRecord{417413a8 #2 A com.gionee.launcher}: ActivityRecord{4177e7e8 com.gionee.launcher/.GNLauncherActivity}
12-30 10:53:59.938: V/ActivityManager(232): Removing and adding at 5
12-30 10:53:59.938: V/ActivityManager(232): At 3 ckp TaskRecord{41c74c08 #118 A gn.com.android.theme}: ActivityRecord{41953dd0 gn.com.android.theme/.ThemeGridActivity}
12-30 10:53:59.938: V/ActivityManager(232): At 2 ckp TaskRecord{41a1f9f0 #37 A com.android.systemui}: ActivityRecord{41a1f828 com.android.systemui/.usb.UsbStorageActivity}
12-30 10:53:59.938: V/ActivityManager(232): At 1 ckp TaskRecord{421ac650 #48 I android/com.android.internal.app.ResolverActivity}: ActivityRecord{41754380 android/com.android.internal.app.ResolverActivity}
12-30 10:53:59.938: V/ActivityManager(232): At 0 ckp TaskRecord{41cdcca0 #8 A com.android.phone}: ActivityRecord{4151eab0 com.android.phone/.InCallScreen}
12-30 10:53:59.969: I/InputDispatcher(232): setInputWindows
12-30 10:53:59.973: D/PhoneStatusBar(311): onReceive, action=android.intent.action.CLOSE_SYSTEM_DIALOGS
12-30 10:53:59.976: D/NetworkPolicy(232): onRecv: MSG_FOREGROUND_ACTIVITIES_CHANGED pid:uid:act=21651:10028:true
12-30 10:53:59.980: V/WindowManager(232): Changing focus from Window{419ae628 com.example.alarmmanager/com.example.alarmmanager.Main paused=true} to null
12-30 10:53:59.981: I/InputDispatcher(232): setInputWindows
12-30 10:53:59.981: I/WindowManager(232): Losing focus: Window{419ae628 com.example.alarmmanager/com.example.alarmmanager.Main paused=true}
12-30 10:53:59.983: D/loc(21651): location=[0, 0]
12-30 10:53:59.988: I/InputDispatcher(232): setInputWindows
12-30 10:53:59.989: I/InputDispatcher(232): setInputWindows
12-30 10:53:59.990: I/InputDispatcher(232): setInputWindows
12-30 10:53:59.990: D/loc(21651): location=[0, 0]
12-30 10:53:59.991: D/jipf-a(21651): onNewIntent intent=Intent { act=android.intent.action.MAIN cat=[android.intent.category.HOME] flg=0x10600000 cmp=com.gionee.launcher/.GNLauncherActivity },mIsOnStop=true
12-30 10:53:59.991: D/04-07(21651): onNewIntent
12-30 10:53:59.991: D/jipf-a(21651): onNewIntent getWindow().isActive()=true
12-30 10:54:00.001: V/AlarmManager(232): Checking for alarms... rtc=1388382840001, elapsed=141219693
12-30 10:54:00.001: V/AlarmManager(232): Checking active alarm when=141219692 Alarm{41d798d8 type 3 android}
12-30 10:54:00.001: V/AlarmManager(232): Alarm triggering: Alarm{41d798d8 type 3 android}
12-30 10:54:00.001: V/AlarmManager(232): Checking active alarm when=141300000 Alarm{416f57b8 type 3 android}
12-30 10:54:00.001: V/AlarmManager(232): Native set alarm :Alarm{416f57b8 type 3 android}
12-30 10:54:00.002: I/AlarmManager(232): bootpackage = com.android.deskclock set Prop 1
12-30 10:54:00.003: D/setVisible(21651): this=CategoryMainMenuLayer: pos[]=[0, 0, 320, 480, 0, 0, 320, 480];isVisible=false;alpha=1.0;bVisible=false;curVisible=false
12-30 10:54:00.003: D/mengqj-area(21651): desktop-rect=Rect(-320, 35 - 640, 416)
12-30 10:54:00.003: D/04-11(21651): setObserverArea
12-30 10:54:00.003: D/04-11(21651): registerArea
12-30 10:54:00.004: D/0518(21651): registerArea dragObserver=com.gionee.launcher.layers.DesktopLayer$3@413f5a00
12-30 10:54:00.005: D/Input(311): VelocityTracker: int datax = 10
12-30 10:54:00.005: D/Input(311): VelocityTracker: int m_velocity_magnify_x = 1.000000
12-30 10:54:00.005: D/Input(311): VelocityTracker: int datay = 10
12-30 10:54:00.005: D/Input(311): VelocityTracker: int m_velocity_magnify_y = 1.000000
12-30 10:54:00.011: D/setVisible(21651): this=ContentLayer: pos[]=[-320, 35, 1920, 376, 0, 0, 1920, 376];isVisible=true;alpha=1.0;bVisible=true;curVisible=true
12-30 10:54:00.011: D/setVisible(21651): this=ImageSView: pos[]=[1, 0, 53, 5, 0, 0, 53, 5];isVisible=false;alpha=0.0;bVisible=false;curVisible=false
12-30 10:54:00.011: D/IcsIndicator(21651): indicatorW:53
12-30 10:54:00.011: D/04-20(21651): w=53;h=5;width=53;height=5
12-30 10:54:00.011: D/setVisible(21651): this=ImageSView: pos[]=[1, 0, 53, 5, 0, 0, 53, 5];isVisible=true;alpha=255.0;bVisible=true;curVisible=true
12-30 10:54:00.012: D/setVisible(21651): this=IcsIndicator: pos[]=[0, 411, 320, 5, 0, 0, 320, 5];isVisible=true;alpha=1.0;bVisible=true;curVisible=true
12-30 10:54:00.012: D/0527(21651): hotseat setVisible bVisible=true
12-30 10:54:00.012: D/0522(21651): size=5
12-30 10:54:00.012: D/mengqj-hs-area(21651): rect=Rect(-320, 416 - 640, 960)
12-30 10:54:00.012: D/mengqj-base(21651): hotSeatLayer-monitorDragArea base=Point(0, 416)
12-30 10:54:00.012: D/04-11(21651): setObserverArea
12-30 10:54:00.012: D/04-11(21651): registerArea
12-30 10:54:00.012: D/0518(21651): registerArea dragObserver=com.gionee.launcher.layers.HotSeatLayer$3@41615328
12-30 10:54:00.012: D/setVisible(21651): this=HotSeatLayer: pos[]=[0, 416, 320, 64, 0, 0, 320, 64];isVisible=true;alpha=1.0;bVisible=true;curVisible=true
12-30 10:54:00.012: D/jipf-onDragDrop(21651): setPageIndex start pageIndex=1;curScreen=1
12-30 10:54:00.012: D/jipf-ind(21651): l=-320;mPageCount=6;displayWidth=320
12-30 10:54:00.012: D/setVisible(21651): this=ImageSView: pos[]=[1, 0, 53, 5, 0, 0, 53, 5];isVisible=false;alpha=255.0;bVisible=false;curVisible=false
12-30 10:54:00.012: D/IcsIndicator(21651): indicatorW:53
12-30 10:54:00.013: D/04-20(21651): w=53;h=5;width=53;height=5
12-30 10:54:00.013: D/setVisible(21651): this=ImageSView: pos[]=[1, 0, 53, 5, 0, 0, 53, 5];isVisible=true;alpha=255.0;bVisible=true;curVisible=true
12-30 10:54:00.013: D/WallPaperProxy(21651): mIsWallpaperScroll:true
12-30 10:54:00.013: D/WallPaperProxy(21651): xStep:0.2
12-30 10:54:00.013: D/WallPaperProxy(21651): xOffset:0.2
12-30 10:54:00.013: D/jipf-ind(21651): l=-320;mPageCount=6;displayWidth=320
12-30 10:54:00.013: D/0606(21651): l=-320;mPageCount=6;displayWidth=320
12-30 10:54:00.013: D/WallPaperProxy(21651): xStep:0.2
12-30 10:54:00.013: D/WallPaperProxy(21651): xstep:0.2,xoffset:0.2
12-30 10:54:00.013: D/jipf-onDragDrop(21651): setPageIndex end pageIndex=1;curScreen=1
12-30 10:54:00.013: I/SurfaceFlinger(95): [SurfaceFlinger] frames:2, duration:1.012000, fps:1.974699
12-30 10:54:00.014: D/setVisible(21651): this=ImageSView: pos[]=[1, 0, 53, 5, 0, 0, 53, 5];isVisible=true;alpha=255.0;bVisible=true;curVisible=true
12-30 10:54:00.015: D/0601(21651): GNLauncher onRestart
12-30 10:54:00.015: D/jipf-a(21651): onRestart mIsOnStop=false
12-30 10:54:00.015: D/0601(21651): GNLauncher onStart
12-30 10:54:00.015: D/jipf-a(21651): onStart mIsOnStop=false
12-30 10:54:00.015: D/0601(21651): GNLauncher onResume
12-30 10:54:00.015: D/jipf-a(21651): onResume mIsOnStop=false
12-30 10:54:00.016: D/WallPaperProxy(21651): drawable.getIntrinsicWidth() =640,drawable.getIntrinsicHeight()=480
12-30 10:54:00.017: D/WallPaperProxy(21651): MultiSpan wallpaper...
12-30 10:54:00.017: D/loc(21651): location=[0, 0]
12-30 10:54:00.018: I/InputDispatcher(232): setInputWindows
12-30 10:54:00.018: D/inv-profiling(21651): mInvRecords.size()=5
12-30 10:54:00.019: D/inval(21651): calcScreenArea dirtyInOut=Rect(0, 0 - 320, 64)
12-30 10:54:00.020: D/inval(21651): calcScreenArea dirtyInOut=Rect(0, 0 - 53, 5)
12-30 10:54:00.020: D/inval(21651): calcScreenArea dirtyInOut=Rect(0, 0 - 320, 480)
12-30 10:54:00.020: D/inval(21651): calcScreenArea dirtyInOut=Rect(0, 0 - 1920, 376)
12-30 10:54:00.020: D/inval(21651): calcScreenArea dirtyInOut=Rect(0, 0 - 320, 5)
12-30 10:54:00.021: D/DRAW-profiling(21651): calc use 2ms; dirty=Rect(0, 0 - 320, 480)
12-30 10:54:00.021: D/wallpaper-cmd(21651): update offset
12-30 10:54:00.021: D/loc(21651): location=[0, 0]
12-30 10:54:00.025: I/InputDispatcher(232): setInputWindows
12-30 10:54:00.026: I/InputDispatcher(232): setInputWindows
12-30 10:54:00.037: I/InputDispatcher(232): setInputWindows
12-30 10:54:00.039: I/AlarmManager(232): rest power off alarm is com.android.deskclock
12-30 10:54:00.041: D/Provider/Setting(232): NameValueTable putString power_off_alarm_package_name in content://settings/system value com.android.deskclock
12-30 10:54:00.042: D/Settings/Provide(232): isRedundantSetValue, oldValuecom.android.deskclockvaluecom.android.deskclock
12-30 10:54:00.042: D/Settings/Provide(232): SettingsCache.isRedundantSetValue power_off_alarm_package_name com.android.deskclock
12-30 10:54:00.042: V/AlarmManager(232): sending alarm Alarm{41d798d8 type 3 android}
12-30 10:54:00.042: V/ActivityManager(232): Broadcast: Intent { act=android.intent.action.TIME_TICK flg=0x40000014 (has extras) } ordered=true
12-30 10:54:00.045: I/InputDispatcher(232): channel '42355730 RecentsPanel (server)' ~ abortBrokenDispatchCycle - notify=false

12-30 11:53:42.675: V/Provider/Setting(30018): invalidate [system]: current 163 != cached 0

回答1:

try like this

Intent myIntent = new Intent(Main.this, AlarmBuzzer.class);
myIntent.putExtra("ActivityName", activity_name);
myIntent.putExtra("ActivityTime", S); //Optional parameters
PendingIntent contentIntent = PendingIntent.getActivity(context, 0, myIntent, 0);