Android 从asyncTask doInBackground调用活动
您好,我正在从一个单独的asyncTask类调用一个基本活动类,当我在一台带有android 4.4.2的设备上运行应用程序时,它工作正常,但当我在带有android 5.0的手机上运行应用程序时,此时从asyncTask应用程序调用活动会崩溃。请告诉我有没有解决办法Android 从asyncTask doInBackground调用活动,android,android-intent,android-asynctask,Android,Android Intent,Android Asynctask,您好,我正在从一个单独的asyncTask类调用一个基本活动类,当我在一台带有android 4.4.2的设备上运行应用程序时,它工作正常,但当我在带有android 5.0的手机上运行应用程序时,此时从asyncTask应用程序调用活动会崩溃。请告诉我有没有解决办法 public abstract class AbstractGetNameTask extends AsyncTask<Void, Void,Void> { private static final String
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" />
但我从不为其他应用而烦恼您应该从onPostExecute开始活动。您只需要从fetchNameFromProfileServer返回结果,而不是从那里启动活动,然后将结果传递到onPostExecute,然后在那里启动活动。您的日志猫在哪里?我告诉过您,在调试模式下,它可以正常工作。。。但在安装apk时,它无法将日志放入try catch块中捕获的内容。安装应用程序后,它仍会将日志记录到logcat。此外,从后台执行在PostExecute上执行也不是一个好主意。可以将代码粘贴到此处。你是怎么做到的?我真正的问题是它在安卓的较低版本上工作,比如在一部手机上运行4.4.2,但在有安卓5.0的手机上不工作。我的清单中有两个开发和-您不应该使用targetSdkVersion 21吗。如果你必须在android 5.0中使用它?