0

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.

Community
  • 1
  • 1
Traveling Salesman
  • 2,209
  • 11
  • 46
  • 83

1 Answers1

1

I think my topic will provide a response to you, even if not perfect. You may also check FelixDroid which is using a different approach seen on other projects. However, I long for a better solution. Going to see if I can find or write a ContextWrapper that will fill the bill.

Full Android support for OSGi bundles

Community
  • 1
  • 1
slash33
  • 899
  • 1
  • 11
  • 17