Search code examples
androidnotificationstoastandroid-contexttrial

How to show popup message without having a context


We are developing a library that will be used both in JVM and Android. And now we need to implement trial period notification. In other platforms (.Net and Mac) showing a popup message box was enough. But so far I cannot find a way to do this for Android.

The problem is that to show some message (toast or AlertDialog), I need to have an actual context. But since our library doesn't contain UI elements and not related to UI in any way we are not asking a user to pass context when creating out components.

To be short:

  • how can I show a Toast (AlertDialog, Notification)without having a context refference passed from user code.
  • If I can't maybe someone have better solutions for implementing trial mode on Android and Java.

Solution

  • It appears that you really can't show neither Toast nor AlertDialog without having a context. The most close variant is to provide some interface in your library that user should implement.