Question

When I close my app and wait some time I get an alert saying "App name has stopped". This only happens after I add the receiver and service tag as you can see in my code below. If I remove them this is not happening, but I receive no push notifications. Im using push notifications from parse.com so the permission and other stuff for GCM is added later.

 <?xml version='1.0' encoding='utf-8'?>
  <manifest android:hardwareAccelerated="true" android:versionCode="4" android:versionName="1.3.0" android:windowSoftInputMode="adjustPan" package="com.guessSound.guessSound" xmlns:android="http://schemas.android.com/apk/res/android">
<supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:resizeable="true" android:smallScreens="true" android:xlargeScreens="true" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<application android:debuggable="false" android:hardwareAccelerated="true" android:icon="@drawable/icon" android:label="@string/app_name">
    <activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:label="@string/app_name" android:name="GuessThisSound" android:screenOrientation="portrait" android:theme="@android:style/Theme.Black.NoTitleBar">
        <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.ParseBroadcastReceiver">
        <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED" />
            <action android:name="android.intent.action.USER_PRESENT" />
            <!-- <category android:name="com.guessSound.guessSound" /> -->
        </intent-filter>
    </receiver>
</application>
<uses-sdk android:minSdkVersion="10" android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.RECORD_VIDEO" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="com.android.vending.BILLING" />
</manifest>

UPDATE

If I use the code below, the alert will not show. So its actually just the service tag that make the error. The com.parse.PushService is a file from the parse.jar

 <manifest android:hardwareAccelerated="true" android:versionCode="4" android:versionName="1.3.0" android:windowSoftInputMode="adjustPan" package="com.guessSound.guessSound" xmlns:android="http://schemas.android.com/apk/res/android">
<supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:resizeable="true" android:smallScreens="true" android:xlargeScreens="true" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.VIBRATE" />
<application android:debuggable="false" android:hardwareAccelerated="true" android:icon="@drawable/icon" android:label="@string/app_name">
    <activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:label="@string/app_name" android:name="GuessThisSound" android:screenOrientation="portrait" android:theme="@android:style/Theme.Black.NoTitleBar">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <receiver android:name="com.parse.ParseBroadcastReceiver">
        <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED" />
            <action android:name="android.intent.action.USER_PRESENT" />
        </intent-filter>
    </receiver>
</application>
<uses-sdk android:minSdkVersion="10" android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.RECORD_VIDEO" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="com.android.vending.BILLING" />
 </manifest>

UPDATE 2.0 Here is my log cat, Im pretty noob at using log cat and since Im using it from the terminal I don't know how to filter.. I hope this give some idea about what might happen

D/widget  (23903): [MSC_HERO_Accu_JB]>>> WC:975 [0:0]  onResume :: fU = true  cEUi = false
D/widget  (23903): [MSC_HERO_Accu_JB]>>> WC:2165 [0:0] AR_S_T : 3
D/widget  (23903): [MSC_HERO_Accu_JB]>>> WC:1011 [0:0]  onResume :: mFAR = false, cC = false, cEUI = false
D/widget  (23903): [MSC_HERO_Accu_JB]>>> WC:1329 [0:0]  cUI : cnt = 1, mRC  = true
D/widget  (23903): [MSC_HERO_Accu_JB]>>> WC:1477 [0:0]  MSL : cityId:current mCL : [CityListItem >> 
D/widget  (23903): CityListItemgetCity() = Rosenborg
D/widget  (23903): CityListItemgetLocation() = cityId:current
D/widget  (23903): CityL

D/widget  (23903): [MSC_HERO_Accu_JB]>>> WC:1477 [1:128] istItemgetLatitude() = 634343143
D/widget  (23903): CityListItemgetLongitude() = 104151998
D/widget  (23903): CityListItemgetProvider() = 1
D/widget  (23903): CityListItemgetState() = S
D/widget  (23903): [MSC_HERO_Accu_JB]>>> WC:1477 [2:256] or-Trondelag, Norway
D/widget  (23903): CityListItemgetRealLocation() =cityId:255551
D/widget  (23903): ]
D/Launcher(23903): ACCESSIBILITY-talkback: false
D/Launcher.HomeFragment(23903): onResume
D/MenuAppsGridFragment(23903): onResume
D/Launcher(23903): onTrimMemory. Level: 15
D/AbsListView(23903): unregisterIRListener() is called 
E/EnterpriseContainerManager( 2347): ContainerPolicy Service is not yet ready!!!
D/EnterpriseDeviceManager( 2347): ContainerId: 0
W/InputMethodManagerService( 2347): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@4394bba8 attribute=android.view.inputmethod.EditorInfo@431f3630, token = android.os.BinderProxy@42fbc8b0
W/LicenseLogService( 2347): log() is called by non admin
D/widget  (23903): [MSC_HERO_Accu_JB]>>> U:127 [0:0] widget 1396278960000
D/widget  (23903): [MSC_HERO_Accu_JB]>>> WC:2118 [0:0] nt=1396278960000
D/widget  (23903): [MSC_HERO_Accu_JB]>>> WC:2119 [0:0] [ARH] now = [1396260420042] lt = [1396278960000] need RF = [false]
D/widget  (23903): [MSC_HERO_Accu_JB]>>> WC:2124 [0:0] nt - now =18539958
D/widget  (23903): [MSC_HERO_Accu_JB]>>> WC:2125 [0:0]  now : 14/03/31 12:07:00 lt : 14/03/31 17:16:00
D/widget  (23903): [MSC_HERO_Accu_JB]>>> U:338 [0:0] win : 7
D/widget  (23903): [MSC_HERO_Accu_JB]>>> WC:721 [0:0] mSUDH(): current loc id = cityId:255551, tZ=GMT+2
D/widget  (23903): [MSC_HERO_Accu_JB]>>> DI:565 [0:0] W Icon : 7
D/widget  (23903): [MSC_HERO_Accu_JB]>>> WC:734 [0:0] ===== mSetUIDataHandler(): day = 6:47 AM, night=8:02 PM
D/widget  (23903): [MSC_HERO_Accu_JB]>>> U:338 [0:0] win : 7
D/widget  (23903): [MSC_HERO_Accu_JB]>>> U:338 [0:0] win : 7
D/widget  (23903): [MSC_HERO_Accu_JB]>>> SM:1259 [0:0] sta ani iPA = false, flkDir = 0, iFA = false
D/widget  (23903): [MSC_HERO_Accu_JB]>>> WC:1800 [0:0] drw all Tm dt
D/widget  (23903): [MSC_HERO_Accu_JB]>>> SM:500 [0:0] set BG2 : false
D/widget  (23903): [MSC_HERO_Accu_JB]>>> SM:519 [0:0] IR : false, IPR : false
D/widget  (23903): [MSC_HERO_Accu_JB]>>> DI:423 [0:0] isd : true nu : 7
D/CellLayoutChildren(23903): setCellDimensions. width: 144, height: 200, gapX: 0, gapY: 0
V/WindowManager( 2347): Window{43202888 u0 Keyguard EXITING}mOrientationRequetedFromKeyguard=false
D/dalvikvm(13113): GC_CONCURRENT freed 510K, 14% free 10797K/12492K, paused 3ms+5ms, total 44ms
D/Launcher(23903): onTrimMemory. Level: 15
D/AndroidRuntime(14166): Shutting down VM
W/dalvikvm(14166): threadid=1: thread exiting with uncaught exception (group=0x41b54700)
D/KeyguardClockWidgetService(32341): onReceive action=android.intent.action.TIME_TICK
E/AndroidRuntime(14166): FATAL EXCEPTION: main
E/AndroidRuntime(14166): java.lang.RuntimeException: Unable to start receiver com.parse.ParseBroadcastReceiver: java.lang.RuntimeException: applicationContext is null. You must call Parse.initialize(context, applicationId, clientKey) before using the Parse library.
E/AndroidRuntime(14166):    at android.app.ActivityThread.handleReceiver(ActivityThread.java:2541)
E/AndroidRuntime(14166):    at android.app.ActivityThread.access$1600(ActivityThread.java:159)
E/AndroidRuntime(14166):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1392)
E/AndroidRuntime(14166):    at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(14166):    at android.os.Looper.loop(Looper.java:176)
E/AndroidRuntime(14166):    at android.app.ActivityThread.main(ActivityThread.java:5419)
E/AndroidRuntime(14166):    at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(14166):    at java.lang.reflect.Method.invoke(Method.java:525)
E/AndroidRuntime(14166):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1046)
E/AndroidRuntime(14166):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:862)
E/AndroidRuntime(14166):    at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime(14166): Caused by: java.lang.RuntimeException: applicationContext is null. You must call Parse.initialize(context, applicationId, clientKey) before using the Parse library.
E/AndroidRuntime(14166):    at com.parse.Parse.checkContext(Parse.java:519)
E/AndroidRuntime(14166):    at com.parse.Parse.getApplicationContext(Parse.java:139)
E/AndroidRuntime(14166):    at com.parse.ManifestInfo.getContext(ManifestInfo.java:221)
E/AndroidRuntime(14166):    at com.parse.ManifestInfo.getPackageManager(ManifestInfo.java:229)
E/AndroidRuntime(14166):    at com.parse.ManifestInfo.getPackageInfo(ManifestInfo.java:240)
E/AndroidRuntime(14166):    at com.parse.ManifestInfo.deviceSupportsGcm(ManifestInfo.java:325)
E/AndroidRuntime(14166):    at com.parse.ManifestInfo.getPushType(ManifestInfo.java:109)
E/AndroidRuntime(14166):    at com.parse.PushService.startServiceIfRequired(PushService.java:150)
E/AndroidRuntime(14166):    at com.parse.ParseBroadcastReceiver.onReceive(ParseBroadcastReceiver.java:20)
E/AndroidRuntime(14166):    at android.app.ActivityThread.handleReceiver(ActivityThread.java:2525)
E/AndroidRuntime(14166):    ... 10 more
V/AlarmManager( 2347): ClockReceiver onReceive() ACTION_TIME_TICK
I/SurfaceFlinger( 1935): id=1760 Removed Leyguard (4/5)
I/SurfaceFlinger( 1935): id=1760 Removed Leyguard (-2/5)
I/ActivityManager( 2347): Notify an ApplicationCrash
I/dumpstate(14182): begin
D/STATUSBAR-IconMerger( 8423): checkOverflow(288), More:false, Req:false Child:2
E/android.os.Debug( 2347): !@Dumpstate > sdumpstate -k -t -z -d -o /data/log/dumpstate_app_error
D/SensorService( 2347):  [AR] -0.3 4.4 8.4
D/SensorService( 2347): AutoRotationSensor::process: Ar_SensorChanged oldrotation = [0], rotation = [255]
D/SSRMv2:Monitor( 2347): SIOP:: AP = 330 (read only)
I/InputReader( 2347): Touch event's action is 0x0 (deviceType=0) [pCnt=1, s=0.11685 ] when=86013816393000
I/InputDispatcher( 2347): Delivering touch to: action: 0x0
I/InputDispatcher( 2347): Delivering touch to: action: 0x0
I/power   ( 2347): *** acquire_dvfs_lock : lockType : 1  freq : 1400000 
D/SSRMv2:CustomFrequencyManagerService( 2347): acquireDVFSLockLocked : type : DVFS_MIN_LIMIT  frequency : 1400000  uid : 10001  pid : 23903  pkgName : com.sec.android.app.launcher@419
I/InputReader( 2347): Touch event's action is 0x1 (deviceType=0) [pCnt=1, s=] when=86013953671000
I/InputDispatcher( 2347): Delivering touch to: action: 0x1
I/InputDispatcher( 2347): Delivering touch to: action: 0x1
E/DatabaseUtils( 2347): Writing exception to parcel
E/DatabaseUtils( 2347): java.lang.SecurityException: Permission Denial: get/set setting for user asks to run as user -2 but is calling from user 0; this requires android.permission.INTERACT_ACROSS_USERS_FULL
E/DatabaseUtils( 2347):     at com.android.server.am.ActivityManagerService.handleIncomingUser(ActivityManagerService.java:13140)
E/DatabaseUtils( 2347):     at android.app.ActivityManager.handleIncomingUser(ActivityManager.java:2038)
E/DatabaseUtils( 2347):     at com.android.providers.settings.SettingsProvider.callFromPackage(SettingsProvider.java:607)
E/DatabaseUtils( 2347):     at android.content.ContentProvider$Transport.call(ContentProvider.java:279)
E/DatabaseUtils( 2347):     at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:273)
E/DatabaseUtils( 2347):     at android.os.Binder.execTransact(Binder.java:388)
E/DatabaseUtils( 2347):     at dalvik.system.NativeStart.run(Native Method)
W/ActivityManager( 2347): Permission Denial: get/set setting for user asks to run as user -2 but is calling from user 0; this requires android.permission.INTERACT_ACROSS_USERS_FULL
D/SSRMv2:CustomFrequencyManagerService( 2347): acquireDVFSLockLocked : type : DVFS_MIN_LIMIT  frequency : 1400000  uid : 10001  pid : 23903  pkgName : LAUNCHER_APP_BOOSTER_CPU@20
D/lights  ( 2347): button : 0 +
D/lights  ( 2347): button : 0 -
D/SensorService( 2347):  [AR] -0.6 5.0 8.4
D/SensorService( 2347): AutoRotationSensor::process: Ar_SensorChanged oldrotation = [255], rotation = [0]
D/SensorService( 2347): AutoRotationSensor::process: Acc  eventTimestamp = 86016098377000, previousAccTimestamp = 86015758897000, difference = 339480000 
D/SSRMv2:Monitor( 2347): SIOP:: AP = 330 (read only)
D/SSRMv2:Monitor( 2347): SIOP:: AP = 330 (read only)
E/Watchdog( 2347): !@Sync 2865
D/SensorService( 2347):   -0.9 5.7 7.8
D/STATUSBAR-NetworkController( 8423): onSignalStrengthsChanged signalStrength=SignalStrength: 9 -1 -1 -1 -1 -1 -1 99 -140 -20 -200 -1 2147483647 gsm|lte 0x3 level=3
I/dumpstate(14182): done
D/SSRMv2:CustomFrequencyManagerService( 2347): acquireDVFSLockLocked : type : DVFS_MIN_LIMIT  frequency : 1200000  uid : 1000  pid : 2347  pkgName : ACTIVITY_RESUME_BOOSTER@5
W/ActivityManager( 2347): mDVFSHelper.acquire()
D/dalvikvm( 2347): GC_FOR_ALLOC freed 1515K, 13% free 48161K/54804K, paused 182ms, total 182ms
I/dalvikvm-heap( 2347): Grow heap (frag case) to 49.263MB for 1127536-byte allocation
D/dalvikvm( 2347): GC_FOR_ALLOC freed 0K, 12% free 49262K/55908K, paused 133ms, total 133ms
V/WindowManager( 2347):  Thread ID Thread[Binder_B,5,main]
D/SSRMv2:CustomFrequencyManagerService( 2347): releaseDVFSLockLocked : Getting Lock type frm List : DVFS_MIN_LIMIT  frequency : 1400000  uid : 10001  pid : 23903  tag : com.sec.android.app.launcher@419
I/power   ( 2347): *** acquire_dvfs_lock : lockType : 1  freq : 1400000 
I/power   ( 2347): *** acquire_dvfs_lock : lockType : 1  freq : 1200000 
D/Launcher.HomeFragment(23903): onPause
D/SSRMv2:CustomFrequencyManagerService( 2347): releaseDVFSLockLocked : Getting Lock type frm List : DVFS_MIN_LIMIT  frequency : 1400000  uid : 10001  pid : 23903  tag : LAUNCHER_APP_BOOSTER_CPU@20
D/SSRMv2:CustomFrequencyManagerService( 2347): FrequencyrequestList.getNextMaxCPUCoreRequest, index: 1
D/CrashAnrDetector( 2347): processName: com.guessSound.guessSound
D/CrashAnrDetector( 2347): broadcastEvent : com.guessSound.guessSound data_app_crash
D/LSO     ( 2347): Unregistered Intent: android.intent.action.sec.LSO_CONFIG_CHANGED , android.intent.action.MEDIA_MOUNTED
I/KeyguardBackgroundView( 2347): *** KeyguardEffectView getInstance ***
V/WindowOrientationListener( 2347): Rotation Sensor : x=255.0
D/GetJar SDK [com.jb.gosms](13841): CONFIG: GetJarConfig()::getInstance() -- re-using existing GetJarConfig instance
V/WindowOrientationListener( 2347): Rotation Sensor : x=0.0
I/InputDispatcher( 2347): Window spent 7203.2ms processing the last input event: MotionEvent(action=0, deviceId=5, source=0x00001002, displayId=0)
V/GetJar SDK [com.jb.gosms](13841): CONFIG: GetJarConfig getDirectiveValue() START [key='usage.package_filter.regex']
I/InputDispatcher( 2347): Window spent 7098.9ms processing the last input event: MotionEvent(action=2, deviceId=5, source=0x00001002, displayId=0)
I/InputDispatcher( 2347): Window spent 7088.3ms processing the last input event: MotionEvent(action=2, deviceId=5, source=0x00001002, displayId=0)
V/GetJar SDK [com.jb.gosms](13841): CONFIG: GetJarConfig getDirectiveValue() Using SERVER defined value: 'usage.package_filter.regex' = '^(com\.)?(android|sec|htc|sonyericsson|motorola|lge|pantech|huawei|asus)(\..*|$)'
I/InputDispatcher( 2347): Window spent 7077.2ms processing the last input event: MotionEvent(action=2, deviceId=5, source=0x00001002, displayId=0)
I/InputDispatcher( 2347): Window spent 7067.2ms processing the last input event: MotionEvent(action=1, deviceId=5, source=0x00001002, displayId=0)
V/GetJar SDK [com.jb.gosms](13841): CONFIG: GetJarConfig getDirectiveValue() FINISHED [key='usage.package_filter.regex']
I/Choreographer( 2347): Skipped 490 frames!  The application may be doing too much work on its main thread.
D/GetJar SDK [com.jb.gosms](13841): USAGE|CONFIG: UsageManager getFilterRegex: ^(com\.)?(android|sec|htc|sonyericsson|motorola|lge|pantech|huawei|asus)(\..*|$)
D/widget  (23903): [MSC_HERO_Accu_JB]>>> WC:1087 [0:0]  onPause 
D/Launcher.Workspace(23903): exitWidgetResizeMode State: NORMAL, newDragStarted: false
V/WindowManager( 2347): Window{43202888 u0 Keyguard}mOrientationRequetedFromKeyguard=false
V/TAG     ( 2347): bug 7643792: fitSystemWindows([0,0][0,0])
V/WindowManager( 2347): rotationForOrientationLw(orient=-1, last=0); user=0  sensorRotation=0 isCoverOpen=true mLidState=-1 mDockMode=0 mHdmiPlugged=false mAccelerometerDefault=false
V/WindowManager( 2347): Application requested orientation -1, got rotation 0 which has compatible metrics
Was it helpful?

Solution

After research without no clue, i realize the following:

First of all, you must call your Parse.initialize(ctx, app_id, clientkey) at the oncreate of a application activity class.

import android.content.res.Configuration;
import android.widget.Toast;


public class ActivityClass extends Application
{

@Override
public void onConfigurationChanged(Configuration newConfig)
{
    super.onConfigurationChanged(newConfig);
}

@Override
public void onCreate()
{

    super.onCreate();

    if(Utils.checkInternetConnection(this))
    {
        Parse.initialize(getApplicationContext(), "aaaaaaaaaaaaaaaaaaaaaaa", "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb");
        PushService.setDefaultPushCallback(this, Splash.class);
        ParseInstallation.getCurrentInstallation().saveInBackground();
    }

}

@Override
public void onLowMemory()
{
    // TODO Auto-generated method stub
    super.onLowMemory();
}

@Override
public void onTerminate()
{
    // TODO Auto-generated method stub
    super.onTerminate();
}



}

then add it in your manifest.xml

  <application
    android:name="PackageName.AplicationClassName"
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" 
    >

Then i also realize that, when was no internet connection, the Parse.BroadCastReceiver couldn't make the inicialization that's why there is this issue. java.lang.RuntimeException: applicationContext is null. You must call Parse.initialize(context, applicationId, clientKey) before using the Parse library.

So, i found the Parse.BroadcastReceiver class on internet which is:

package com.parse;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

public class ParseBroadcastReceiver extends BroadcastReceiver {
private static final String TAG = "com.parse.ParseBroadcastReceiver";

@Override
public void onReceive(Context context, Intent intent) {
    Log.d(TAG, "received " + intent.getAction());
    PushService.startServiceIfRequired(context);
}
}

and i put it in my classes then i modified the entire class to manipulate when to launch the "PushServices.startServices" action only when the device have internet connection.

-

public class ParseBroadcastReceiverCustom extends BroadcastReceiver {
private static final String TAG = "com.parse.ParseBroadcastReceiver";

@Override
public void onReceive(final Context context, Intent intent) {
    Log.d(TAG, "received " + intent.getAction());
    Utils.checkInternetConnection2(context, new CallBackFunction()
    {
        @Override
        public void FunctionToCall(String obj)
        {
            if(obj.equals("true"))
            {
                PushService.startServiceIfRequired(context);
            }

        }
    });

}
}

This is the Utils function i use to check internet connection

public static void checkInternetConnection2(Context ctx,final CallBackFunction call)
{
    boolean response = false;

    ConnectivityManager conMgr = (ConnectivityManager) ctx
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo i = conMgr.getActiveNetworkInfo();
    if (i == null)
        response = false;
    else if (!i.isConnected())
        response = false;
    else if (!i.isAvailable())
        response = false;
    else
        response = true;

    if(response)
    {

    CustomAsynctask TestTask = new CustomAsynctask(new CallBackFunction()
    {

        @Override
        public void FunctionToCall(String obj)
        {
            String url = "http://www.parse.com";
            String test = Utils.getStringFromUrl(url);

            if(test.equals(""))
            {
                real_answer = false;
            }
            else
            {
                real_answer = true;
            }
            call.FunctionToCall(real_answer+"");

        }
    }); 

    TestTask.execute((Void[])null);

    }
    else
    {
        call.FunctionToCall(response+"");
    }

}

Then, at the manifest i add my own customize Parse.BroadcastReceiver.

<receiver android:name="com.mypackagename.ParseBroadcastReceiverCustom">
      <intent-filter>
        <action android:name="android.intent.action.BOOT_COMPLETED" />
        <action android:name="android.intent.action.USER_PRESENT" />
        <action android:name="android.net.wifi.WIFI_STATE_CHANGED"/>
        <action android:name="android.net.wifi.STATE_CHANGE"/>
      </intent-filter>
    </receiver>

It works for me, no more error messages in my device screen!!!! :)

If it works for you, please rate it!!! Before i found this, was no solution.... Thanks!!!!

P.D. The others Classes i use!!!

Callbackfunction Java

package com.wigilabs.Utils;

public interface CallBackFunction {

public void FunctionToCall(String obj);

}

CustomAsyncTask Java

package com.wigilabs.Utils;



import android.os.AsyncTask;

public class CustomAsynctask extends AsyncTask<Void, Void, String>{

private CallBackFunction functionToCall;

public CustomAsynctask(CallBackFunction f) {
    this.functionToCall = f;
}

@Override
protected String doInBackground(Void... params) {
    functionToCall.FunctionToCall("");
    return null;
}

 }

OTHER TIPS

I found this post in Parse questions:

"I suspect you are calling Parse.initialize from your main Activity's onCreate. This doesn't work though if the push service starts before your main Activity (i.e. it usually loads on device boot). Create an Application class and register it in your AndroidManifest.xml. If you move your Parse.initialize into its onCreate method, your program will always call Parse.initialize before the service starts."

https://parse.com/questions/android-push-notification-error-msg

A simplified solution maybe :

Build a class extending ParseBroadcastReceiver :

public class CustomParseReceiver extends ParseBroadcastReceiver {
     @Override
     public void onReceive(Context context, Intent intent) {
         if(context != null){
             if(Utilities.isNetworkAvailable(context))super.onReceive(context, intent);
         }
     } 
}

The Utilitles isNetworkAvailable is as follows :

 public static boolean isNetworkAvailable(Context context) {
    ConnectivityManager connectivityManager
            = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
    return activeNetworkInfo != null && activeNetworkInfo.isConnected();
 }

And in your manifest.xml change the com.parse.ParseBroadcastReceiver to the custom receiver.

<service android:name="com.parse.PushService" />
      <receiver android:name=".CustomParseReceiver">
          <intent-filter>
              <action android:name="android.intent.action.BOOT_COMPLETED" />
              <action android:name="android.intent.action.USER_PRESENT" />/>
          </intent-filter>
 </receiver>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top