open an activity from a CordovaPlugin

前端 未结 6 1909
深忆病人
深忆病人 2020-12-13 06:27

I have written a CordavaPlugin derived class.

public class ShowMap extends CordovaPlugin {

@Override
public boolean execute(String action, JSONArray args,
          


        
6条回答
  •  半阙折子戏
    2020-12-13 07:19

    1. Register your activity in the AndroidManifest file
    2. In your plugin you should have the code like this, notice no "callback.success()" is called
    3. Run the action in ui thread and not background thread.
    4. enjoy

      if (action.equals("myaction")) {
          cordova.getActivity().runOnUiThread(new Runnable() {
              @Override
              public void run() {
                  Context context = cordova.getActivity()
                          .getApplicationContext();
                  Intent intent = new Intent(context, MyNewActivityGap.class);
                  cordova.getActivity().startActivity(intent);
              }
          });
      
          return true;
      }
      

提交回复
热议问题