[英]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.