【发布时间】:2016-01-29 04:09:17
【问题描述】:
你好,我从一个单独的 asyncTask class 中调用 base activity class,当我在 一台装有 android 4.4.2 的设备上运行应用程序时,它工作正常,但是当我在具有 的手机上运行它时>android 5.0 然后在此时从 asyncTask 应用程序调用活动崩溃。请问有人有解决办法吗?
public abstract class AbstractGetNameTask extends AsyncTask<Void, Void,Void>
{
private static final String TAG = "TokenInfoTask";
protected ActivityLogin mActivity;
public static String GOOGLE_USER_DATA="No_data";
protected String mScope;
protected String mEmail;
protected int mRequestCode;
private ProgressDialog pDialog;
private Context mContext;
AbstractGetNameTask(ActivityLogin activity, String email, String
scope,Context context) {
this.mActivity = activity;
this.mScope = scope;
this.mEmail = email;
this.mContext=context;
}
@Override
protected void onPreExecute() {
// TODO Auto-generated method stub
pDialog = new ProgressDialog(mContext);
pDialog.setTitle("Loading....");
pDialog.setMessage("Please wait...");
pDialog.setCancelable(false);
pDialog.setMax(100);
pDialog.show();
super.onPreExecute();
}
@Override
protected Void doInBackground(Void... params) {
try {
fetchNameFromProfileServer(); // here in this method i start new activity
} catch (IOException ex) {
onError("Following Error occured, please try again. "
+ ex.getMessage(), ex);
} catch (JSONException e) {
onError("Bad response: " + e.getMessage(), e);
}
return null;
}
}
我的安卓清单有
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />
但它从不打扰我其他应用程序
【问题讨论】:
-
你的 logcat 在哪里??
-
我告诉过你,在调试模式下它工作正常......但在安装 apk 时它不起作用
-
把你捕捉到的日志放在
try-catch块中。 -
应用安装后仍会记录到 logcat。
-
另外,从后台执行开始活动也不是一个好主意,请在 postExecute 上执行
标签: android android-intent android-asynctask