How to use an intent to update an activity?

You can create new BroadcastReceiver instance and do something along these lines on your Activity's onResume() method: registerReceiver(myReceiver, new IntentFilter(DownloadService. ACTION_FILE_DOWNLOADED)) After that, override myReceiver's onReceive() method to call a function that updates the component you want: Override public void onReceive(Context context, Intent intent) { ... updateViewWithData(service.getNewFileData()); ... } On your Activity's onPause() method, just unregister the receiver: unregisterReceiver(myReceiver) I hope that this would help you, feel free to ask if there is something unclear.

You can create new BroadcastReceiver instance and do something along these lines on your Activity's onResume() method: registerReceiver(myReceiver, new IntentFilter(DownloadService. ACTION_FILE_DOWNLOADED)); After that, override myReceiver's onReceive() method to call a function that updates the component you want: @Override public void onReceive(Context context, Intent intent) { ... updateViewWithData(service.getNewFileData()); ... } On your Activity's onPause() method, just unregister the receiver: unregisterReceiver(myReceiver); I hope that this would help you, feel free to ask if there is something unclear.

The good way to do this is to bind your "Downloaded files" activity to the service. When you bind the service, in the function onServiceConnected, register a Binder callback. Then, whenever you have new data available, service just calls that callback.

If the activity is not running, the callback list at the service side will be empty, so it will not inform your activity. For an example of this approach, take a look at RemoteService. Java in Android SDK: samples\ApiDemos\src\com\example\android\apis\app.

Seems you don't need the receiver element in the manifest as you have registered your receiver dynamically , I am not very certain, you may have a try :P.

Thanks, attatching the broadcastReciever at runtime seems to work, but I could not get it to work when I tried to bind it in the manifest xml. This works : In my activity I added: private MyReceiver reciever; protected void onPause(){ super.onPause(); unregisterReceiver(reciever); } protected void onStart(){ super.onStart(); reciever = new MyReceiver(this); registerReceiver(reciever, new IntentFilter("Gurba")); } //...attatched to button... public void onClick(View arg0) { Log. I("dbg", "clickkkk"); Intent myIntent = new Intent("Gurba"); sendBroadcast(myIntent); } And my MyReciever class as follow: public class MyReceiver extends BroadcastReceiver { private Activity activity; public MyReceiver(Activity activity) { this.

Activity = activity; Log. I("dbg","MyReciever created"); } public void onReceive(Context context, Intent intent) { Log. I("dbg","onRecieve() called!"); if(this.

Activity == null); } } This did NOT work: private MyReceiver reciever; protected void onPause(){ super.onPause(); } protected void onStart(){ super.onStart(); reciever = new MyReceiver(this); } and added to the AndroidManifest. Xml Main" ... continue manifest... when I click my button I just get a runtime-exception: unable to instantiate receiver com.example. MyReciever .... Any ideas on this?

Something missing in my XML?

When the download is done, I would like to update my "Downloaded files" list in my Activity, but only if the Activity is running. I do not want the Activity to start if it's not already running. I was hoping I could do this by making a new Intent with some special flag.

Anyone have any idea how I can achieve this? A tiny code example maybe?

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions