1

In my app the pdf is downloaded on clicking the thumbnial and a progress indicator shows the downloaded progress, when the downloaded is completed a broadcast is fired from downloaded class and in main activity broadcast receiver is registered and adapter.notifyDataSetChanged(); acts. and the progress indicator goes invisible which is my requirement but My problem is this when the main activity goes to background and downloaded is completed the progress indicator does not go invisible. when user go back to the activity

BroadcastReceiver receiver=new BroadcastReceiver() 
{
@Override
 public void onReceive(Context context, Intent intent) {
 adapter.notifyDataSetChanged();
    }
};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

     setContentView(R.layout.gridview);
    new DownloadJSON().execute();
}

@Override
protected void onResume() {
    super.onResume();
    registerReceiver(receiver,new IntentFilter("com.download.complete"));
}

  @Override
public void onStop() {
    super.onStop();
    unregisterReceiver(receiver);

//on completion of downloading pdf, broadcast is fired context.sendBroadcast(intent);

ebbi
  • 45
  • 8

2 Answers2

1

You unregister the receiver in the onStop() method. Whenever the activity goes in background you don't have a listening receiver. Hence, notifyDataSetChanged() is not called and your action is not performed.

Umang
  • 966
  • 2
  • 7
  • 17
0

pls modify your onResume() method

@Override
protected void onResume() {
    if (adapter !=null) {
        adapter.notifyDataSetChanged();
    }
    registerReceiver(receiver,new IntentFilter("com.download.complete"));
    super.onResume();
}
Manish
  • 1,071
  • 2
  • 10
  • 27