我有一个带有ProgressDialog的Android应用程序,当它连接时,它启动了一个计时器。该应用有时会崩溃,但出现以下错误:
var metaRetriever:MediaMetadataRetriever = MediaMetadataRetriever()
metaRetriever.setDataSource(filePath)
var out:String = ""
var txtTime:String = ""
var duration:String = metaRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION)
Log.d("DURATION VALUE", duration)
var dur:Long = duration.toLong()
var seconds:String = ((dur % 60000)/1000).toString()
Log.d("SECONDS VALUE", seconds)
var minutes:String = (dur / 60000).toString()
out = minutes + ":" + seconds
if (seconds.length == 1){
txtTime = "0" + minutes + ":0" + seconds
}
else {
txtTime = "0" + minutes + ":" + seconds
}
Log.d("MINUTES VALUE", minutes)
Log.d("FORMATTED TIME", txtTime)
metaRetriever.release()
这是我的代码:
java.lang.IllegalArgumentException: View=DecorView@47b2334[Connecting] not attached to window manager
at android.view.WindowManagerGlobal.findViewLocked(WindowManagerGlobal.java:508)
at android.view.WindowManagerGlobal.removeView(WindowManagerGlobal.java:417)
at android.view.WindowManagerImpl.removeViewImmediate(WindowManagerImpl.java:136)
at android.app.Dialog.dismissDialog(Dialog.java:446)
at android.app.Dialog.dismiss(Dialog.java:429)
at com.trackme.Post.onPostExecute(Post.java:145)
at com.trackme.Post.onPostExecute(Post.java:43)
at android.os.AsyncTask.finish(AsyncTask.java:667)
at android.os.AsyncTask.-wrap1(AsyncTask.java)
at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:684)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6816)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1563)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1451)
答案 0 :(得分:0)
当您尝试将进度对话框附加到已被破坏的活动或在后台运行时,会出现此错误。通过以下方法检查活动是否正在运行:
activity.isfinishing()
如果为假,则附加progressdialog
。
@Override
protected void onPreExecute() {
progressDialog.setTitle("Connecting");
progressDialog.setMessage("Trying to connect to your server. Please wait...");
progressDialog.setCancelable(false);
progressDialog.setCanceledOnTouchOutside(false);
if(!context.isFinishing()){
progressDialog.show();
}
}