1

The android Fragments tutourial teaches how to send data from a fragment to activity in using Interfaces. I don't understand interfaces that much and NOBODY gives a good example of how to use them not even docs.oracle.com. What I want to know is how to recreate something like LocationListener, where I:

1) implement the interface in class A

2) set the handler for example :setInterfaceHandler(this) in class A

3) add my implementation of the interface in class A foe Example:

public void onSomethingHappened(String s)
{
  // do this
}

4) periodically have class B fire off events that will be caught by the handler class in A

For example: Android will periodically give my activity location updates (Dont know how to do this).

Uwe Plonus
  • 9,803
  • 4
  • 41
  • 48
FutureSci
  • 1,750
  • 1
  • 19
  • 27

1 Answers1

1

Of course you can use Java language mechanisms and design patterns for your purpose (interfaces, handlers, ...) ... or you might have a look at some dedicated Android framework solutions for your problem like:

With these approaches you are able to fire your events from class B and handle them in class A with a clean and "android like" design.

André Diermann
  • 2,725
  • 23
  • 28