In the for-loop below the last putExtra overrides the first putExtra even though they take different parameters and different vars.
First: putExtra(String,String)
Second: putExtra(String, int)
Note: videos[i] is a String array
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);
}
In my DownloadService which extends IntentService the value from VIDEOS is null !!
Why is that ?
EDIT:
This is the part of the code in my DownloadService class:
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,”Downloading (” + fileNr + “/77)”);
in the bold text there fileNr i need to get the fileNr from the other activity but it’s giving me null in this case…
In your Question the
key are always remain same for different values that’s why,,
try to use
and get result like,
EDIT: try this code..
And one more thing if you are passing
array of integerand someArray of video URIthen please try to useand avoid loop..
Thanks.