FileDownloader:
public class FileDownloader implements Parcelable {
int file_size = 0;
// Ignore other logic code here
public int get_file_size() {
return file_size;
}
public void start() {
Intent download_service = new Intent(context, DownloadService.class);
download_service.putExtra("download_manager", this);
context.startService(download_service);
}
}
DownloadService
public class DownloadService extends Service {
@Override
public int onStartCommand(final Intent intent, int flags, int startId) {
FileDownloader download_manager =
intent.getParcelableExtra("download_manager");
download_manager.file_size = 2000;
}
}
DemoActivity:
FileDownloader fd = new FileDownloader();
fd.start(new ProgressUpdateListener () {
@Override
public void on_update(int downloaded_size) {
// the value is still 0
fd.get_file_size();
}
});
The problem is that when the FileDownloader object passed by parcel to service. and file_size has new value in service, and the value in activity doesn't change. They don't share the same object reference?