【问题标题】:How to pass string from cordova plugin to activity in android如何将字符串从cordova插件传递到android中的活动
【发布时间】:2015-01-17 18:13:36
【问题描述】:

我有用于cordova 的活动和插件。我需要从插件中获取字符串值并希望将此字符串发送到活动。我使用了捆绑包、getextra、putextra 等。但我总是将值设为空。请回复。我用谷歌搜索,但没有得到解决方案。我的代码如下。

插件代码: 上下文上下文=this.cordova.getActivity().getApplicationContext(); Intent intent=new Intent(context,First.class);

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

    context.startActivity(intent);

在我的活动代码处:

    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+"");

    }

【问题讨论】:

    标签: java android cordova


    【解决方案1】:
        String id = intent.getStringExtra("Id");
    

    试试这个,你在plugin中设置id并在activity中获取id,因为这个原因它总是null

    【讨论】:

    • 你能详细说明一下吗??
    • 在 onCreate 中,您正在搜索“id”键,而您的意图是输入“Id”。它区分大小写...
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-27
    • 1970-01-01
    相关资源
    最近更新 更多