extending Application oncreate

RadCoder

Member
Licensed User
Longtime User
Erel I read in one of your posts that we cannot write a library to extend application onCreate. Here is the problem, I am using the Parse SDK. I wrote a library to wrap it, similar to what Agraham has recently done.
To support receiving of parse push messages, Parse states that when your app in no longer in memory, we need to run Parse.Initialize in Application onCreate such that Parse.initialize is called before the ParsePush service is started to.

I tried "extends" application in a library and even called super.oncreate in the call after my parse.initialize but like Agrahams parse library, weird things happen in the b4a runtime (DIP don't calculate properly for example)

Without extending application How would I solve this problem ?
 

warwound

Expert
Licensed User
Longtime User
There's no problem sub classing the Application class in a B4A library - i've done it a few times.

I posted an example here: http://www.b4x.com/forum/libraries-...20-trying-create-acra-library.html#post113855.

As long as your Application sub class has no errors then all you need to do is modify the manifest, setting the name of the Application sub class:

B4X:
SetApplicationAttribute(android:name, "fully.qualified.application.subclass.name")

Martin.
 
Upvote 0

RadCoder

Member
Licensed User
Longtime User
Thanks for the responses, I have the subclass working but the weird behavior I'm experiencing is the b4a density global variable is wrong when i subclass application on the siii. Will test further to try and pinpoint the cause or hopefully its limited only to the siii
 
Upvote 0

warwound

Expert
Licensed User
Longtime User
I tried "extends" application in a library and even called super.oncreate in the call after my parse.initialize but like Agrahams parse library, weird things happen in the b4a runtime (DIP don't calculate properly for example)

B4X:
public class MyApplication extends Application {
    @Override
    public void onCreate() {
        super.onCreate();
        BA.Log("MyApplication onCreate");
        // try your code after calling super.onCreate()
    }
}

Only thing i can suggest is to call super.onCreate() before initializing your Parse stuff.
If you can't fix it then post your Application class.

Martin.
 
Upvote 0

RadCoder

Member
Licensed User
Longtime User
thanks your code snippnet is almost identical to mine but still doesnt fix the problem. i have tried using it with @Override and without, same output

Below is my code, very simple. Now in activity create or anywhere in your app output the density value

Log("density:" & Density)

on my devices, siii and even an old htc desire, density is always 1 when you subclass application which is wrong(siii should be 2 htc desire should be 1.5). this messes up all dip calculations so if you use DIP in your app, the display is now wrong and shruken

B4X:
public class xParse extends Application
{
 
public void onCreate()
  {
      super.onCreate();
      Parse.initialize(this, myappID, myclientKey);

  }
}
 
Last edited:
Upvote 0

RadCoder

Member
Licensed User
Longtime User
thanks Erel, I found the problem. Its related to the following line of code I have in my oncreate:

anywheresoftware.b4a.keywords.Common.Log("xParse init success")

irregardless where I use common.log during oncreate, density is messed up in B4a

If I log using android.utils :

Log.v("init", "xParse init success " );

no problems. Not sure if this is a bug but wanted to let you know. I probably should have never have used a b4a call during app startup anyhow....

thanks again
 
Upvote 0
Top