I am trying to display a Toast message in an OSGI Bundle which obviously uses the Android API. The toast needs an application context so I thought of creating an activity first inside my bundle. Here's my activity class with the toast message:
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toast.makeText(this.getApplicationContext(), "This is OSGI Bundle", Toast.LENGTH_SHORT).show();
}
}
Now I would like to start the above activity from my start() method in the Bundle Activator class. below is that class:
public class Activator implements BundleActivator {
private static BundleContext context;
static BundleContext getContext() {
return context;
}
public void start(BundleContext bundleContext) throws Exception {
Activator.context = bundleContext;
//I WOULD LIKE TO START THE ACTIVITY HERE TO DISPLAY THE TOAST MESSAGE
}
public void stop(BundleContext bundleContext) throws Exception {
Activator.context = null;
}
}
How can I achieve that? The only way I am aware of to start an activity is when you are in another activity like here, which is not my case. Can someone help? Thank you.