如何将带有额外内容的意图发送到图书馆项目活动 [英] How to send Intent with extras to Library Project Activity

查看:25
本文介绍了如何将带有额外内容的意图发送到图书馆项目活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个包含一项活动的库项目.我已经将这个库项目引用到我的主项目中.我试图通过意图调用带有一些额外内容的图书馆项目活动.但是在库项目中检索 getIntent.getExtras 时出现空指针异常.知道如何做到这一点吗?

I have created a library project with one activity. I have given reference of this library project to my Main Project. I am trying to call Activity of Library Project with some extras through intent. But I am getting null pointer exception while retrieving getIntent.getExtras in Library Project. Any idea how to do this?

我正在开始图书馆项目的活动,如下所示:

I am starting activity of Library Project like below:

    Intent intent = new Intent(activity,com.***.***.LibActivity.class);
    intent.putExtra("key", "abcds");
    activity.startActivity(intent);

我正在尝试检索 LibActivity 中的密钥(在库项目中),如下所示:

And I am trying to retrieve the key in LibActivity (Which is in library project) like below:

getIntent().getExtras().getString("key") -->在这一行抛出空指针异常

getIntent().getExtras().getString("key") -->Throwing null pointer exception at this line

我已将此活动添加到我的主要项目清单中.

I have added this activity to my Main Projects manifest.

推荐答案

你必须在你的主项目中传递这个

You have to pass this on your main project

Intent myIntent= new Intent(this,YourActivity.class);
myIntent.putExtra("shopId", shopId);
this.startActivity(myIntent);

在你的图书馆活动中你必须通过这个

And in your Library activity You have to pass just this

String intentdata = this.getIntent().getStringExtra("shopId");

然后你的工作就完成了!

Then boom your work is done!

这篇关于如何将带有额外内容的意图发送到图书馆项目活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆