0

I recently upgraded my parse-*.jar files to version 1.10.0 After cleaning up my project at android studio and syncing with gradle, suddenly my app freezes at start... blackscreen, without any button working (I need to force-close the app)

I searched the net and this site for solutions, but couldn't find anything.

Any help will be much appreciated!

My Application class:

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

Thanks in advance!

EDIT:

my manifest:

<?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>
Re'em
  • 1,869
  • 1
  • 22
  • 28

2 Answers2

0

Shouldn't you initialize the parse sdk before anything else

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);
            }
        }
    });

}

Brian
  • 4,328
  • 13
  • 58
  • 103
  • logcat: Caused by: java.lang.IllegalStateException: `Parse#enableLocalDatastore(Context)` must be invoked before `Parse#initialize(Context)` – Re'em Aug 22 '15 at 15:43
0

To anyone who might be concerned, Apparently there was no Internet connection for the phone (because it automatically went into USB tethering and something went wrong over there) so that when parse got initialized it tried to connect to the server AT THE MAIN THREAD without success, causing the freeze effect.

The solution was to check for the phone's connectivity BEFORE starting parse, so my final solution was -

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);
    }
    ....
}

I chose one of the methods to check connectivity which exist here - How to check internet access on Android? InetAddress never times out

Have a good day!

Community
  • 1
  • 1
Re'em
  • 1,869
  • 1
  • 22
  • 28