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