我想在下载完成时刷新或重新启动片段(下载管理器),但代码必须在Fragment类中。
我使用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));