0

我面临着令人头疼的问题,无法解决。这里有人可以帮忙吗...

我有一个活动(父母)开始另一个活动(孩子)。我正在从子活动中启动下载管理器。当我单击子活动上的按钮以查看下载时,它会打开下载管理器并显示下载。到此为止,一切都很顺利。但是当我通过按回车键从这个下载视图窗口返回时,大部分时间它都会崩溃(特别是在下载完成时)。不知道为什么。。

注意:当我从父活动启动下载管理器时,一切正常。但我需要从孩子开始。任何帮助将不胜感激。

我正在开始儿童活动,例如:

lv.setOnItemClickListener(new AdapterView.OnItemClickListener(){
public void onItemClick(AdapterView<?> p, View v, int position, long id) {
    Intent i = new Intent(AudioDownloadActivity.this,CDPageActivity.class);
    i.putExtra("audioCDURL", "http://bkdrluhar.com/00-htm/" + hiddenText);
    i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    AudioDownloadActivity.this.startActivity(i);
}});

在子活动中,为下载管理器定义和启动广播接收器,例如:

private long enqueue;
private DownloadManager dm;
/*some code */
BroadcastReceiver receiver = new BroadcastReceiver() {
    @Override
    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();
        if (DownloadManager.ACTION_DOWNLOAD_COMPLETE.equals(action)) {
            Query query = new Query();
            query.setFilterById(enqueue);
            Cursor c = dm.query(query);
            if (c.moveToFirst()) {
                int columnIndex = c.getColumnIndex(DownloadManager.COLUMN_STATUS);
                if (DownloadManager.STATUS_SUCCESSFUL == c.getInt(columnIndex)) {
                }
            }
        }
    }
};
registerReceiver(receiver, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));

/*some code */
dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
Request request = new Request(Uri.parse(downloadURL));
request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI | DownloadManager.Request.NETWORK_MOBILE)
    .setAllowedOverRoaming(true).setTitle("BK Asset")
    .setDescription(tempFile)
    .setDestinationUri(Uri.fromFile(new File(MainActivity.downloadFileLocation,tempFile)));        
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
enqueue = dm.enqueue(request);  

按下弹出的按钮会显示下载:

public void onAudioCDDownloadClick(View v){
    Intent i = new Intent();
    i.setAction(DownloadManager.ACTION_VIEW_DOWNLOADS);
    startActivity(i);       
}

此崩溃的日志 cat 是:

FATAL EXCEPTION: main                                                                                                                                                                                             
java.lang.RuntimeException: Error receiving broadcast Intent { act=android.intent.action.DOWNLOAD_COMPLETE flg=0x10 pkg=com.os.bkdownloader (has extras) } in com.os.bkdownloader.AudioDownloadActivity$1@416b8ad8
    at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:737)                                                                                                                                      
    at android.os.Handler.handleCallback(Handler.java:605)                                                                                                                                                        
    at android.os.Handler.dispatchMessage(Handler.java:92)                                                                                                                                                        
    at android.os.Looper.loop(Looper.java:137)                                                                                                                                                                    
    at android.app.ActivityThread.main(ActivityThread.java:4517)                                                                                                                                                  
    at java.lang.reflect.Method.invokeNative(Native Method)                                                                                                                                                       
    at java.lang.reflect.Method.invoke(Method.java:511)                                                                                                                                                           
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:995)                                                                                                                            
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:762)                                                                                                                                               
    at dalvik.system.NativeStart.main(Native Method)                                                                                                                                                              
Caused by: java.lang.NullPointerException                                                                                                                                                                         
    at com.os.bkdownloader.AudioDownloadActivity$1.onReceive(AudioDownloadActivity.java:158)                                                                                                                      
    at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:728)                                                                                                                                      
4

0 回答 0