简体   繁体   English

通知意图putextra方法

[英]notification intent putextra method

I am working on a download manager . 我正在从事下载管理器。 for managing notifications every second it calls two methods sequentially which build notification by getbroadcast . 为了每秒管理通知,它依次调用了两个通过getbroadcast建立通知的方法。 updateActiveNotification(downloads) And then updateCompletedNotification(downloads) . updateActiveNotification(downloads),然后updateCompletedNotification(downloads)。 the first method checks my download list and builds an appropriate notification which is supposed to show the download progress(it builds the notifications every second and so it looks like ongoing notification!) , the second one checks for completed downloads and builds their notifications. 第一种方法检查我的下载列表并构建一个适当的通知,该通知应显示下载进度(它每秒生成一次通知,因此它看起来像正在进行的通知!),第二种方法检查是否已完成下载并构建其通知。 Now the problem is that I set data through putExtra in these two methods for both on-going download and completed downloads, but when I get the intents in my receiver I can't get the putExtra data from the completed download intents and actually the data keys are from the first method . 现在的问题是,我通过这两种方法的putExtra设置了正在进行的下载和完成的下载的数据,但是当我在接收器中获得意图时,我无法从完成的下载意图中获取putExtra数据,实际上是从数据中获取数据键来自第一种方法。 I'm confused like hell! 我很迷糊! . these are two different methods which make different intents for different notifications . 这是两种不同的方法,它们针对不同的通知做出不同的意图。 How is this possible. 这怎么可能。 Can anybody help me?! 有谁能够帮助我?!
Here is the example code : 这是示例代码:

first method : 第一种方法:

Intent intent = new Intent(action);
Intent.setclass(receiver class)
intent.putExtra("someName1", boolean);
context.getbroadcast(intent);

second method : 第二种方法:

Intent intent = new Intent(action);
Intent.setclass(receiver class)
intent.putExtra("someName2", boolean);
context.getbroadcast(intent);

now on reciever: 现在正在接收:

Bundle mybundle = intent.getExtras();
    if(mybundle != null) {
        for (String key : mybundle.keySet()) {
            //Object value = mybundle.get(key);
            Log.d("ALA-Dev", key);
        }
    }

for both intents (from the first method or the second one) it prints someName2 as the key ,meaning it dose's not get the second data at all! 对于这两种方法(从第一种方法或第二种方法),它都会打印someName2作为键,这意味着它根本不会获得第二个数据!

Difficult to give a qualified answer without code examples. 没有代码示例很难给出合格答案。 If you provided an extra like this: 如果您提供了这样的额外功能:

Intent intent = new Intent(context, SomeActivity.class);
intent.putExtra("someName", someString);
context.startActivity(intent);

Then you can get the data back using soemthing like this: 然后,您可以使用类似以下的方式获取数据:

Intent intent = getIntent();
String yourExtra = intent.getStringExtra("someName");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM