Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Vijay_R_3
Beginner
164 Views

How to define an Application Class to override the default onCreate

Hello,

I am trying to implement Parse Plugin for using Push Notification Services. Please advise me how to implement the below procedure for an Android App in Intel XDK. I tried creating a dummy plugin with an MainApplication Class and also adding the <application> tag in plugin.xml for getting included in AndroidManifest.xml, but it is not working.

https://github.com/taivo/parse-push-plugin

------------------------------------

Android Setup:

Phonegap/Cordova doesn't define a custom android.app.Application, it only defines an android Activity. With anActivity alone, we should be able to receive PNs just fine while our app is running. However, if a PN arrives when the app is not running, the app will be automatically invoked, and this plugin's ParsePushPluginReceiver runs before the Activityclass or any javascript code gets a chance to call Parse.initialize(). The result is a crash dialog. To fix this, do the following:

  1. Define a custom Application class that calls Parse.initialize() in its onCreate method. This way, the Parse subsystem gets initialized before the PN-handling code runs. Crash avoided. In your application's Java source path, e.g.,platforms/android/src/com/example/app, create a file named MainApplication.java and define it this way

    package com.example.app;  //REPLACE THIS WITH YOUR package name
    
    import android.app.Application;
    import com.parse.Parse;
    import com.parse.ParseInstallation;
    
    public class MainApplication extends Application {
        @Override
        public void onCreate() {
            super.onCreate();
            Parse.initialize(this, "YOUR_PARSE_APPID", "YOUR_PARSE_CLIENT_KEY");
            ParseInstallation.getCurrentInstallation().saveInBackground();
        }
    }
  2. Now register MainApplication in AndroidManifest.xml so it's used instead of the default. In the <application> tag, add the attribute android:name="MainApplication". Obviously, you don't have to name your application class this way, but you have to use the same name in 1 and 2.

 ------------------------------------

Tags (2)
0 Kudos
1 Reply
PaulF_IntelCorp
Employee
164 Views

Our support staff is not able to provide help with writing plugins. Your best bet for this sort of help would be to use the Cordova threads on StackOverflow.

Reply