English 中文(简体)
当你有多重警报时,可以发出单一警报
原标题:Cancelling a single alarm when you have multiple alarms

I have used the same pendingIntent to set multiple alarms using different intentId for each. the alarm is working. Now i want to cancel a particular alarm. If i use the cancel() method i would end up cancelling all the alarms. I want only a specific one to be deleted. Also the user should be able to cancel this alarm even during a second or a third launch. As in when i launch it the second time, i won t be having the same pendingIntent object. Would i have to persist the pendingIntent object? If so, how? and how do i cancel a single alarm from multiple alarms?

最佳回答

你可以这样做。

在您尚未获得许可的情况下,您可通过<代码>unique ID,取代requestCode

PendingIntent pi = PendingIntent.getBroadcast(context, unique_id, i, 0);

取消后,你可以使用相同的独一无二的身份证,以取消该身份证,同时使用同样的待决身份。

am.cancel(pi);

为了获得更多信息,你只能使用StackOverflow或谷歌,现在我想>> 回答 页: 1

问题回答

这里需要作解释。

首先,你们应当为即将到来的意图创造独特的意图。 为此,你可以建立一个习惯数据领域,说明你打算申请。 我这样做的方式如下:

Intent intent = new Intent();
intent.setAction(ExampleAppWidgetProvider.MY_INTENT_ACTION);
Uri data = Uri.withAppendedPath(
                Uri.parse("myapp://myapp/Id/#"),
                String.valueOf(intentId));
intent.setData(data);

页: 1 Id将是您独特的意向识别符号。

接着,你发出警报 管理人员通知照例。 取消警报,请采取以下步骤。 首先,你们应当像以往的法典样本那样,产生意图。 然后,你根据这一意图制造了未决意图(你也制造了同样的预想,以引起警惕)。 然后,你取消这一警告:

Intent intent = new Intent();
intent.setAction(ExampleAppWidgetProvider.MY_INTENT_ACTION);
Uri data = Uri.withAppendedPath(
                Uri.parse("myapp://myapp/Id/#"),
            String.valueOf(intentId));
intent.setData(data);


PendingIntent pendingIntent = PendingIntent.getBroadcast(
                context, 0, intent,
                PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
alarmManager.cancel(pendingIntent);




相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签