Java Question Help Please raising an event.

dealsmonkey

Active Member
Licensed User
Longtime User
Hi all,

After playing with the Xtify SDk for push notifications, I am able to register my device and then recieve a test message which is show in the logs..:D

However I am having a newb problem !

I have my main class that is called from B4A :

B4X:
public class nejoC2DM{

public void connectToPush(BA ba, String eventName){

code here to connect to Xtify Servers..
}
}

The code then calls a second public class that overrides the Broadcast receiver :

B4X:
public class receiver extends BroadcastReceiver
{
         
      public Neoreceiver(){
      super();
      
   }
   
      
   static String T = "";
   static String B = "";
   
   @Override
   public void onReceive(Context context, Intent intent) {
      // TODO Auto-generated method stub
      
      Log.i("MESSGAE", "Got Here");
         
      abortBroadcast();
      if (intent.hasExtra("NOTIFICATION_TITLE") && intent.hasExtra("NOTIFICATION_DETAILS")) {
         
         T = intent.getStringExtra("NOTIFICATION_TITLE");
         B = intent.getStringExtra("NOTIFICATION_DETAILS");
         Log.i("MESSGAE", "******** " +  T + " : : " + B + " ******");
         
                           
               }
                  
   }
   
   
} //end class

What I am struggling to comprehend is how I can raise an event for B4A and pass the Strings.
 

eps

Expert
Licensed User
Longtime User
You could define them in the topmost sub and they will be available to other activities or services.. it depends how many we're talking about.
 

dealsmonkey

Active Member
Licensed User
Longtime User
You could define them in the topmost sub and they will be available to other activities or services.. it depends how many we're talking about.

All I am looking to do is raise and event when the message is received and pass back the title and body of the message.

Thanks

neil
 

dealsmonkey

Active Member
Licensed User
Longtime User
Look here for a code fragment for an event.


Thanks for the info, had a look.

What I am struggling with is the class that the message void is in does not have a BA object as it is called by the main class.

Can I pass the BA to the second message received class or can I raise an event without the ba ?

neil
 

dealsmonkey

Active Member
Licensed User
Longtime User

I have tried to set the BA as public using get and set in the main class, but I am getting a null value in the second class :

main class

B4X:
public BA getba(){      
      return _ba;            
   }
      
   public void setba(BA tba){      
      _ba = tba;                     
   }

Second class in message OnReceive Void

B4X:
MainClass mc = new MainClass();   
      
this._Aba =mc.getba();
 

dealsmonkey

Active Member
Licensed User
Longtime User
No, it won't work "MainClass mc = new MainClass();" won't have a BA instance. I'd need to see your code as I think the structure of your library is not correct.

Here you go, thanks for taking the time to have a look :)

Neil
 

Attachments

  • push.zip
    1.5 KB · Views: 294

agraham

Expert
Licensed User
Longtime User
The easiest to get it to work, though not very elegant, is to make C2DMReceiver._Aba and _eventName public static variables and set them in MainClass.Initialize. Using RaiseEvent assumes that the Broadcast Receiver onXXX methods are always called on the main UI thread, which I believe to be the case.

By the way, you don't need a separate file for SecondReceiverClass. If you include it in MainClass and declare it static then it will behave as if it were a separate class and not a nested class.

I note you spelt "Initialise" the English way. I have adopted "Initialize" for my libraries as that is what the official Basic4android libraries use.

I don't think your SecondReceiverClass needs to be visible to Basic4android code so it doesn't need a ShortName attribute.
 

dealsmonkey

Active Member
Licensed User
Longtime User
The easiest to get it to work, though not very elegant, is to make C2DMReceiver._Aba and _eventName public static variables and set them in MainClass.Initialize. Using RaiseEvent assumes that the Broadcast Receiver onXXX methods are always called on the main UI thread, which I believe to be the case.

Doing this has solved the problem. I can now raise a B4A event and pass the message :sign0098:

By the way, you don't need a separate file for SecondReceiverClass. If you include it in MainClass and declare it static then it will behave as if it were a separate class and not a nested class.

I will sort this as soon as I get things working


I note you spelt "Initialise" the English way. I have adopted "Initialize" for my libraries as that is what the official Basic4android libraries use.

Changed to Initialize

I don't think your SecondReceiverClass needs to be visible to Basic4android code so it doesn't need a ShortName attribute.

I have removed this
 
Top