您好我正在尝试重现pendingIntents以取消它们......
但我真的不明白上下文,getBaseContext(),getApplicationContext()是如何工作的以及我需要的......
问题在于,当我创建它们时,它是一个简单的函数,现在我在listView的onItemLongClick函数中,然后在对话界面...
以下是代码:
[已编辑] - 使用ReglagesActivity.this这是我的OuterClass但现在我有一个java.lang.NullPointerExecption:/ 但是我测试了我的对象是否为null或者不是......:/
[编辑2] - 忘记重新创建我的alarm_Manager对象...我的错><
ListNotifs.setOnItemLongClickListener(new OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> parent, View v, final int position, long id) {
final AlertDialog.Builder b = new AlertDialog.Builder(ReglagesActivity.this);
// set title
b.setTitle("Suppression de l'alarme");
// set dialog message
b
.setMessage("Souhaitez-vous vraiment supprimer cette alarme ?")
.setCancelable(false)
.setPositiveButton("Oui",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int id) {
// SUPPRESS
// Get number of the alarm :
HashMap<String, String> hash = listItem.get(position);
String num_str = hash.get("description");
String[] spliit = num_str.split(" ");
String splited = spliit[spliit.length-1];
int num = Integer.parseInt(splited);
//Re-create intent for cancel :
try {
Intent intent = new Intent(ReglagesActivity.this, AlarmReceiver.class);
// Here is the probleme for context i tried this : Makes the app crash ^^ :
PendingIntent alarm_intent = PendingIntent.getBroadcast(ReglagesActivity.this.
getApplicationContext(),num,intent, PendingIntent.FLAG_NO_CREATE);
if ( alarm_intent != null && intent != null )
{
try
{
alarm_Manager.cancel(alarm_intent);
}
catch (IndexOutOfBoundsException e)
{
Toast.makeText(getBaseContext(), "[Erreur] alarme mal supprimée\n\n"+e.toString() , Toast.LENGTH_SHORT).show();
}