[英]How to send intent data from main project to library project in android?
我一直在尝试将数据从我的主项目发送到我的图书馆项目。 我的库项目是在主项目中定义的,所以添加 lib 项目的依赖没有问题。我发现还有一个线程与我的问题类似,但到目前为止没有运气...... 线程
GetUserprofile是主项目的活动, LockscreenActivity是库项目的活动。
我在主项目端写了代码
Intent myIntent = null;
try {
myIntent = new Intent(GetUserprofile.this,LockscreenActivity.class);
myIntent.putExtra("examiddetails",exam_id);
startActivity(myIntent);
} catch (Exception e) {
e.printStackTrace();
}
现在我使用以下代码获取库项目中的examiddetails数据
Intent intent = getIntent();
try{
if(intent != null){
String Examid = intent.getStringExtra("examiddetails");
}
}catch(Exception e){
System.out.println("getdataFromService exception"+e.toString());
}
我在库项目中得到了 Examid String 的空值。
从您的应用程序创建意图
Intent myIntent= new Intent(this,YourActivity.class)
myIntent.putExtra("data", "value");
从图书馆获取意图
string intentdata = ((Activity)getContext()).getIntent().getStringExtra("data");
你的意思是将数据发送到另一个活动? 我以前也做过。
主项目类
Intent intent= new intent(getApplication(), LockscreenActivity.class);
intent.putExtra("examiddetails",exam_id);
startActivity(intent);
LockscreenActivity 类
Bundle bundle = getIntent().getExtras();
String ExamIdDetails = bundle.getString("examiddetails");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.