Access to the main project class from the library class

I have an Android project that uses a library project (everything I created). I use ADT / SDK v14, and I need to access the main class in the main project and call the function when the dialog in the library project is rejected. Now I can do this by adding a link to my main project in the library project, but this is not ideal. How to get a class reference in my main project from a class in a library project?

Here's how it works:

  • I have my main class in my project which is tabhost
  • Tabhost gets tabbed snippets from library project
  • One of the tab snippets launches the DialogFragment dialog box
  • When this DialogFragment is rejected, I need to call the fillItems () function in the main class (this is where I got stuck)

Does anyone have any ideas?

Thanks Ed

+5
source share
1 answer

How to get a class reference in my main project from a class in a library project?

Ideally, you do not.

Instead, you:

  • Define the interface in the library that contains the methods you want to call, the implementation of which comes from the main project
  • Inject this interface into some likely class in your main project
  • Delivery of this implementation to the library through some setter or using the constructor argument
  • Ask the library if necessary to call interface implementation methods
  • , - ,

" " - , .

+5

All Articles