我最近将我的解析 - * .jar文件升级到版本1.10.0 在android studio清理我的项目并与gradle同步后,突然我的应用程序在开始时冻结...黑屏,没有任何按钮工作(我需要强制关闭应用程序)
我搜索网络和本网站寻找解决方案,但无法找到任何结果。
非常感谢任何帮助!
我的申请类:
public class Application extends android.app.Application {
@Override
public void onCreate() {
super.onCreate();
Log.d("app", "reached1");
// Enable Local Datastore.
Parse.enableLocalDatastore(this);
Log.d("app", "reached2");
ParseObject.registerSubclass(FoodListItem.class);
Log.d("app", "reached3");
Parse.initialize(this, "STRING1", "STRING2");
Log.d("app", "reached4");
ParseInstallation.getCurrentInstallation().saveInBackground();
Log.d("app", "reached5");
ParsePush.subscribeInBackground("", new SaveCallback() {
@Override
public void done(ParseException e) {
if (e == null) {
Log.d("app", "successfully subscribed to the broadcast channel.");
} else {
Log.e("app", "failed to subscribe for push", e);
}
}
});
}
logcat的:
08-17 21:46:58.554 17633-17633/il.ac.huji.freefood D/dalvikvm﹕ Late-enabling CheckJNI
08-17 21:46:58.594 17633-17633/il.ac.huji.freefood W/ActivityThread﹕ Application il.ac.huji.freefood can be debugged on port 8100...
08-17 21:46:58.604 17633-17633/il.ac.huji.freefood D/app﹕ reached1
08-17 21:46:58.604 17633-17633/il.ac.huji.freefood D/app﹕ reached2
08-17 21:46:58.614 17633-17633/il.ac.huji.freefood D/app﹕ reached3
提前致谢!
修改:
我的清单:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="il.ac.huji.freefood" >
<uses-sdk android:minSdkVersion="11" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<permission
android:name="il.ac.huji.freefood.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="il.ac.huji.freefood.permission.C2D_MESSAGE" />
<application
android:name="il.ac.huji.freefood.Application"
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme"
>
<activity android:name=".activities_one_class.MainActivity" />
<activity android:name=".activities_one_class.NoFoodFoundActivity" />
<activity android:name=".activity_choose_food.ChooseFoodActivity" />
<activity android:name=".activity_add_food.AddFoodActivity" />
<activity android:name=".GPS_tracker_Activity" />
<activity android:name=".activities_one_class.SignUpActivity" />
<activity android:name=".activities_one_class.LoginActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:name="com.parse.PushService" />
<receiver android:name="com.parse.GcmBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="il.ac.huji.freefood" />
</intent-filter>
</receiver>
<receiver
android:name="il.ac.huji.freefood.PushNotificationsReceiver"
android:exported="false">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.USER_PRESENT" />
<action android:name="com.parse.push.intent.RECEIVE" />
<action android:name="com.parse.push.intent.OPEN" />
<action android:name="com.parse.push.intent.DELETE" />
</intent-filter>
</receiver>
<meta-data
android:name="com.parse.push.notification_icon"
android:resource="@drawable/pooh_icon" />
<!--TODO once it was android:resource="@drawable/ic_launcher" />-->
</application>
</manifest>
答案 0 :(得分:0)
不应该在其他任何事情之前初始化解析sdk
public class Application extends android.app.Application {
@Override
public void onCreate() {
super.onCreate();
Parse.initialize(this, "STRING1", "STRING2");
Parse.enableLocalDatastore(this);
ParseObject.registerSubclass(FoodListItem.class);
ParseInstallation.getCurrentInstallation().saveInBackground();
ParsePush.subscribeInBackground("", new SaveCallback() {
@Override
public void done(ParseException e) {
if (e == null) {
Log.d("app", "successfully subscribed to the broadcast channel.");
} else {
Log.e("app", "failed to subscribe for push", e);
}
}
});
}
答案 1 :(得分:0)
对于任何可能担心的人,显然手机没有互联网连接(因为它会自动进入USB网络共享并且出现问题),以便在解析初始化时尝试连接到主服务器THREAD没有成功,导致冻结效果。
解决方法是在开始解析之前检查手机的连接性,所以我的最终解决方案是 -
public class Application extends android.app.Application {
@Override
public void onCreate() {
super.onCreate();
Log.d("app", "reached1");
if (!connectedToInternet()) {
Log.e("app", "not connected to internet. exiting");
exitAppWithDialog(this);
}
....
}
我选择了其中一种检查此处存在的连接的方法 - How to check internet access on Android? InetAddress never times out
祝你有个美好的一天!