对于旧设备,我的应用程序崩溃,下面是我得到的错误。
try {
Class.forName("android.os.AsyncTask");
}
catch(Throwable ignore) {
// ignored
}
知道我做错了吗?
根据research我尝试在onCreate of SplashActivity&也在AppController中。
<application
android:name=".AppController"
android:allowBackup="true"
android:icon="@drawable/app_logo"
android:label="@string/app_name"
android:largeHeap="true"
android:theme="@style/AppTheme"
tools:replace="android:icon">
<activity
android:name=".SplashActivity"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:theme="@style/AppTheme.NoActionBar"
android:windowSoftInputMode="adjustResize|stateHidden">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
以下是我在Manifest文件中的内容。
new AsyncTask<Void, Void, String>() {
@Override
protected String doInBackground(Void... params) {
String msg = "";
try {
if (gcm == null) {
gcm = GoogleCloudMessaging.getInstance(context);
}
regid = gcm.register(SENDER_ID);
msg = "Device registered, registration ID=" + regid;
Log.i("SplashReg.", "------ >> Registeration msg == " + msg);
if (!languageSeassionManager.isRegIdToken()) {
languageSeassionManager.setRegId(regid);
languageSeassionManager.setNotificationStatus(true);
}
} catch (IOException ex) {
msg = "Error :" + ex.getMessage();
// If there is an error, don't just keep trying to register.
// Require the user to click a button again, or perform
// exponential back-off.
}
return msg;
}
@Override
protected void onPostExecute(String msg) {
// make request to to post the data
// PostDeviceData postData = new PostDeviceData();
// postData.execute();
Log.e("registeration id ", regid);
String url = getString(R.string.AddTokenForAndroid);
String userId = (sessionManager.isLoggedin()) ? sessionManager.getUserCode() : "0";
String myURL = url
+ "?token="
+ regid
+ "&deviceId="
+ android_id + "-" + deviceId
+ "&deviceType=2";
Log.d("myURL_push", myURL);
StringRequest req = new StringRequest(Request.Method.GET, myURL
,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
if (!isBackButtonPressed) {
startActivity(new Intent(SplashActivity.this, LanguageActivity.class));
overridePendingTransition(R.anim.fade_in, R.anim.fade_out);
finish();
}
}
}, 2000);
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.e("error ", error.getMessage() + " " + error.toString());
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
if (!isBackButtonPressed) {
startActivity(new Intent(SplashActivity.this, LanguageActivity.class));
overridePendingTransition(R.anim.fade_in, R.anim.fade_out);
finish();
}
}
}, 2000);
}
});
// Adding request to request queue
req.setShouldCache(false);
req.setRetryPolicy(new DefaultRetryPolicy(10 * 1000, 2, 1.0f));
req.setTag(TAG);
AppController.getInstance().addToRequestQueue(req, TAG);
}
}.execute(null, null, null);
}
在Splash活动中,我正在为推送通知注册设备令牌。以下是我的相同内容。我在 onCreate
中有此代码01-17 10:11:40.320 531-531/app.myappname E/GooglePlayServicesUtil: The Google Play services resources were not found. Check your project configuration to ensure that the resources are included.
01-17 10:11:40.330 531-531/app.myappname I/GCM Demo: Registration not found.
01-17 10:11:40.330 531-531/app.myappname E/dalvikvm: Could not find class 'app.myappname.SplashActivity$1$1', referenced from method app.myappname.SplashActivity$1.onPostExecute
我发现的其他错误如下。
{{1}}
答案 0 :(得分:1)
错误似乎与您的SplashActivity
本身无关,而是与其正在使用的类之一有关。
正如我从您的代码中看到的,这些类可能是原因:GoogleCloudMessaging
,StringRequest
和AppController
。我认为使用较旧的Android API级别的旧设备不支持这些Google类