简体   繁体   English

如何将字符串从Cordova插件传递到Android中的活动

[英]How to pass string from cordova plugin to activity in android

I have activity and plugin for cordova.I need to get string value from the plugin and want to send this string to activity.I used the bundle, getextra, putextra etc.But always i'm getting value as null. 我有科尔多瓦的活动和插件。我需要从插件中获取字符串值,并想将此字符串发送给活动。我使用了bundle,getextra,putextra等,但是我总是以null的形式获取值。 Please reply. 请回复。 I googled, but didn't got solution. 我用谷歌搜索,但没有解决方案。 My code is as below. 我的代码如下。

Plugin code: Context context=this.cordova.getActivity().getApplicationContext(); 插件代码:Context context = this.cordova.getActivity()。getApplicationContext(); Intent intent=new Intent(context,First.class); Intent intent = new Intent(context,First.class);

    intent.putExtra("Id", "MyData");

    context.startActivity(intent);

At my activity code: 在我的活动代码中:

    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.intent);
          Intent intent = getIntent();
          intent.getStringExtra(String name) method. In your case:

            String id = intent.getStringExtra("Id");
            Log.i("ID":id+"");

    }
    String id = intent.getStringExtra("Id");

尝试此操作,在插件中设置ID并在活动中获取ID,因此,它始终为null

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM