gpt4 book ai didi

android - putExtra 覆盖其他 putExtra

转载 作者:行者123 更新时间:2023-11-29 14:55:33 25 4
gpt4 key购买 nike

在下面的 for 循环中,最后一个 putExtra 覆盖了第一个 putExtra,即使它们采用不同的参数和不同的变量。

首先:putExtra(String,String)第二:putExtra(String, int)

注意:video[i]是一个String数组

 Intent intent = new Intent(this,DownloadService.class);
for(int i=0;i<videos.length;i++){
intent.putExtra("VIDEOS",videos[i]);
intent.putExtra("FILENR",(i + 1));
startService(intent);

}

在我扩展 IntentService 的 DownloadService 中,VIDEOS 的值为 null !!这是为什么?

编辑:这是我的 DownloadService 类中的部分代码:

Intent broadcastIntent = new Intent();
notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, null, 0);

notification = new Notification(R.drawable.icon, "Skitips", System.currentTimeMillis());
contentView = new RemoteViews(getPackageName(), R.layout.progress_layout);
notification.flags = Notification.FLAG_AUTO_CANCEL;
notification.contentView = contentView;
notification.contentIntent = contentIntent;
contentView.setProgressBar(R.id.status_progress, 100, 0, false);
contentView.setTextViewText(R.id.status_text,"Downloading...");

String full_url = "";

full_url = URL + intent.getStringExtra("VIDEOS");

String fileName = "";

fileName = intent.getStringExtra("VIDEOS");

String fileNr = "";

fileNr = intent.getStringExtra("FILENR");


int count;






Log.e("Whattttttt","is the value of VIDEOOOOSSSS: " + full_url);
Log.e("Whatttt","is the value of fileNrrrrrrrrrrrr:" + fileNr);
try {
URL url = new URL(full_url);
URLConnection conexion = url.openConnection();
conexion.connect();
File file = new File(root.getPath(), fileName);

int lenghtOfFile = conexion.getContentLength();
Log.d("ANDRO_ASYNC", "Lenght of file: " + lenghtOfFile);

InputStream input = new BufferedInputStream(url.openStream());
OutputStream output = new FileOutputStream(file);

byte data[] = new byte[1024];

long total = 0;

contentView.setTextViewText(R.id.status_text,"下载中("+ fileNr + "/77)");

在粗体文本中有 fileNr 我需要从其他 Activity 中获取 fileNr 但在这种情况下它给了我 null ...

最佳答案

那是因为 putExtra() 将数据添加到 HashMap 中。对于 hashmap,如果您使用相同的键,则先前的值将被最新的值覆盖。

关于android - putExtra 覆盖其他 putExtra,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7738829/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com