0

I have a program with about 8 Activity classes, and 1 Application class. I want my Application class to be able to communicate with every Activity, but on its own terms. I don't want the activity to ask the Application for data, I want the Application to send the Activity data. The problem with this, is that depending on the current state of the program I'm unsure what Activity will be open.

Is there a method of some sort which will send information from the Application to the CURRENT activity?


The Application class connects with an embedded Bluetooth Device and needs to receive different pieces of data depending on which Activity the user is currently in. I originally had it as a regular class, which was initialized in the MainMenu of my program and passed a Handler. However, it seemed like weak design to pass that Handler from Activity to Activity time and time again.

Bill the Lizard
  • 398,270
  • 210
  • 566
  • 880
JuiCe
  • 4,132
  • 16
  • 68
  • 119
  • 1
    No there is no such method, neither the android-architecture is so, anything you'l do in this way will be at risk of breaking any time. May be you can share details so that some one can come up with a different architecture for your requirement. –  Jun 22 '12 at 13:08
  • 1
    why you needed to "end information from the Application to the CURRENT activity" because all the visible to you is Current Activity and all the thing being handled by Current activity, where as Application has no direct user interaction ................. – Dheeresh Singh Jun 22 '12 at 13:13
  • @ dj aqeel: when I said it is not possible with reason, you said that answer is waist for OP now you are alos saying same......... – Dheeresh Singh Jun 22 '12 at 13:16
  • 1
    I think he didn't understand your post. It seemed like you were telling me to use the getApplication() method to do what I had asked. – JuiCe Jun 22 '12 at 13:17
  • @DheereshSingh your answer was not worth an answer, it was more of a comment. So it should have been a comment, –  Jun 26 '12 at 13:45
  • @dj aqeel: stay on your words .. previously you given some other reason and now a new one....... – Dheeresh Singh Jun 26 '12 at 13:48
  • @DheereshSingh I don't remember what your answer was exactly. But if you said it is not possible(even with a reason) than it should be a comment.. –  Jun 26 '12 at 13:51
  • @dj aqeel: just skip this you are just trying to proof your self right but I have not time for arguments....Even this is not a right place for this ...... – Dheeresh Singh Jun 26 '12 at 13:56

1 Answers1

1

You could use a Callback Method

Every Activity has it's own callback method and registers that method onResume() in the Application Class. (it's like an onApplicationWantsToDoSomethingWithMeListener() ;)

or why not a Service in background? instead of the Application, since what you want sounds like a Service. More details?

EDIT: I made a similar application with bluetooth, you should definetly use a Service for that, but you can communicate with your service per Application. Say the Service calls the callback in the Application look here for an implementation uf such a thing

Community
  • 1
  • 1
trichner
  • 840
  • 1
  • 11
  • 22
  • Thanks a lot, I've been looking for a similar example all over the place and haven't found one this close yet – JuiCe Jun 22 '12 at 13:41
  • it's all under the GPL license, copy as much as you like, write me if you have further questions – trichner Jun 22 '12 at 13:50