0
我想在下載完成時刷新或重新啓動片段(下載管理器),但代碼必須在片段類中。刷新下載的片段在android中完成
我使用Broadcast Receiver在下載完成時重新啓動片段。但代碼不起作用。 MyFragment.java
BroadcastReceiver onComplete=new BroadcastReceiver() {
public void onReceive(Context ctxt, Intent intent) {
Toast.makeText(getActivity(), "Download Complete", Toast.LENGTH_LONG).show();
getActivity().getSupportFragmentManager().beginTransaction()
.detach(getTargetFragment())
.attach(getTargetFragment()).commit();
}
};
getActivity().registerReceiver(onComplete, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));