在後臺使用AsyncTask啓動的線程中,我請求root訪問權限。如果拒絕(未找到),我想告訴用戶。我知道你不能直接從後臺線程發佈到UI線程,但是當我測試它時,通過對主要活動的引用這樣做似乎很有效。現在,它的出版市場,但是,這些錯誤報告:來自線程的Android對話框
java.lang.RuntimeException: An error occured while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:266)
at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
at java.util.concurrent.FutureTask.run(FutureTask.java:137)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1081)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:574)
at java.lang.Thread.run(Thread.java:1020)
Caused by: java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
at android.os.Handler.<init>(Handler.java:121)
at android.app.Dialog.<init>(Dialog.java:100)
at android.app.AlertDialog.<init>(AlertDialog.java:96)
at android.app.AlertDialog$Builder.create(AlertDialog.java:891)
at com.sajarvis.albert.AlbertActivity.onCreateDialog(AlbertActivity.java:357)
at android.app.Activity.onCreateDialog(Activity.java:2747)
at android.app.Activity.createDialog(Activity.java:948)
at android.app.Activity.showDialog(Activity.java:2825)
at android.app.Activity.showDialog(Activity.java:2789)
at com.sajarvis.albert.AlbertActivity$HiyaTask.doInBackground(AlbertActivity.java:507)
at com.sajarvis.albert.AlbertActivity$HiyaTask.doInBackground(AlbertActivity.java:1)
at android.os.AsyncTask$2.call(AsyncTask.java:252)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
... 4 more
下面是對話創造者的代碼(行349-360)
case 1: //su denied
Log.w(TAG,"Su denied failure");
builder
.setTitle(R.string.su_denied_title)
.setMessage(R.string.su_denied_message)
.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
}).create();
break;
和線條501-511背景線程,我在那裏調用失敗的對話框。
//Get ROOT access.
try {
process = Runtime.getRuntime().exec("su");
} catch (IOException e1) {
//TODO crashes here
activity.showDialog(1);
FlurryAgent.onError("4","su denied","Fail");
return success; //False, fail.
}
Is activity.showDialog(1);什麼導致了崩潰?如果是這樣,爲什麼它不會一致崩潰。如果不是,有什麼想法是什麼?非常感謝。
你創建AsyncTask的線程是什麼?在您的AsyncTask中AlertDialog創建是在哪裏開始的? –
我從主要活動UI線程創建任務。 AsyncTask中對話框的唯一行是activity.showDialog(1)。這在UI線程中調用onCreateDialog()。 – jarvisteve