alarmmanager

Stop the background service after particular time in android

瘦欲@ 提交于 2019-12-08 14:01:26
Hi i need to stop the Background service which is already started after particular time.I will get the duration from server for when to stop the service.I have tried the Alarm Manager in android. Calendar cal = Calendar.getInstance(); Intent intent = new Intent(context, MyService.class); PendingIntent pintent = PendingIntent.getService(context, 0, intent, 0); AlarmManager alarm = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE); // Start every 30 seconds alarm.setRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), 60*1000, pintent); Log.e(TAG, "Service started in Activity");

How to repeat the alarm for “n” days at a particular time

久未见 提交于 2019-12-08 13:09:12
问题 This is my code to set the alarm for every 24 hours. How can I repeat this for 20 days only? alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), 24*60*60*1000, pendingIntent); 回答1: that will be repeating forever until you cancel it. So, what you can do, it's to fire something in 20 days,and when managing that event, cancel your alarm. 来源: https://stackoverflow.com/questions/7347120/how-to-repeat-the-alarm-for-n-days-at-a-particular-time

IntentService, PendingIntent, and AlarmManager: Cannot keep process running indefinitely?

我的未来我决定 提交于 2019-12-08 12:08:22
问题 I've got a pretty simple app that runs two services in the background, using IntentService with AlarmManager. One is a "messaging" service that sends a JSON request and parses the response, the other polls for location from a LocationManager. The requirement here is that they run on an interval, indefinitely, until manually stopped by the user, with a button - even if the device's screen hasn't been turned on for days. The services must never stop. Battery life is not a concern. My minimum

how to repeat an alarm android?

試著忘記壹切 提交于 2019-12-08 11:25:39
问题 How to repeat an alarm manager to run my activity once in 30 minutes? How to simply run this main activity once in 30 minutes can anybody explain me pls code : import android.app.Activity; import android.os.Bundle; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } } 回答1: private void setLocationSendingAlarm() { AlarmManager alarmManager = (AlarmManager)

AlarmManager does not wakeup at right time on Samsung Phone

本小妞迷上赌 提交于 2019-12-08 10:21:34
问题 On some Samsung phones we unfortunately had to find out that the AlarmManager (SamsungAlarmManager) does not work like expected. Our code is: private void scheduleNextSamplingIntent(final Context context, final int intervalInMillis) { Log.v(TAG, "scheduleNextSamplingIntent | intervalInMillis = " + intervalInMillis); if (intervalInMillis <= 0) { Log.w(TAG, "scheduleNextSamplingIntent | invalid interval " + intervalInMillis); return; } long currentTimeMillis = DeviceClock.getInstance()

Android: Cancel an Alarm Set From Another Activity

谁都会走 提交于 2019-12-08 07:01:04
问题 I will try to explain this as best as I can. Basically, I have Activity 1 that uses an ExternalClass to do various things. Activity 2 also references Activity 1's object of said ExternalClass. From both of these activities I can set alarms using the AlarmManager, but I want to be able to cancel all the alarms created from either activity, from Activity 1. All alarms are set using the same intent and the same AlarmManger (both created in the ExternalClass), but when I click my button in

Android Alarm Manager Set Repeating at Specific Timing

半城伤御伤魂 提交于 2019-12-08 06:44:47
问题 I am having some problem with alarm manager in Android. So what I am trying to do is set the alarm to repeat to run the DB insertion every day around 12.01AM. Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(System.currentTimeMillis()); calendar.set(Calendar.HOUR_OF_DAY, 0 ); calendar.set(Calendar.MINUTE, 1); notificationCount = notificationCount + 1; AlarmManager mgr = (AlarmManager) context .getSystemService(Context.ALARM_SERVICE); Intent notificationIntent = new Intent

FusedLocationAPI can not remove location updates through AlarmManager

大兔子大兔子 提交于 2019-12-08 05:57:37
问题 I have created simple class to get updated location using google's FusedLocationProviderClient . i.e.: public class LocationProvider extends LocationCallback {... private static FusedLocationProviderClient mFusedLocationClient; private LocationRequest mLocationRequest; if(mFusedLocationClient == null) { mFusedLocationClient = LocationServices.getFusedLocationProviderClient(mContext); mFusedLocationClient.requestLocationUpdates(mLocationRequest, locationCallback, null /* Looper */); }..} Now,

Using JobService to replace BroadcastReceiver? Network changes and alarms

霸气de小男生 提交于 2019-12-08 04:01:35
问题 It's becoming increasingly frustrating trying to get NetworkInfo working. I posted a question, but I guess people haven't seen it. Anyway, I really need a solution based on my flow below. I need to know when my network changes so I can determine what kind of network it is and then make decisions based off that answer. I thought, OK, maybe I'll try JobService, but I am not having a lot of luck trying to puzzle out how to use it for my needs. My app is reactive and happens all behind the scenes

AlarmManager alarm does not trigger after the phone resets

♀尐吖头ヾ 提交于 2019-12-08 02:29:41
问题 In my app the user joins a plan, then the next day at noon there is an alarm notification. Here is my code: First, I set an alarm in AlarmManager like so: //set alarm to the next day 12:00 noon of the join date SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); try { alarm_date = format.parse(join_date); } catch (ParseException e) { e.printStackTrace(); } GregorianCalendar calender = new GregorianCalendar(); calender.setTime(alarm_date); calender.add(Calendar.DATE, 1); calender.add