[英]How to transfer boolean value between activities in android?
這就是我目前正在做的事情,但它只是強制關閉應用程序。
在第一個活動中
Intent myIntent = new Intent(Input.this, results.class);
myIntent.putExtra("perfect", rig);
startActivity(myIntent);`
我要轉移到的活動
Boolean lovers = getIntent().getExtras().getBoolean("perfect");
正如文檔所說,函數是getBooleanExtra
Boolean lovers = getIntent().getExtras().getBooleanExtra("perfect");
我不確定接受的答案 :: 但我認為應該是
Boolean lovers = getIntent().getExtras().getBoolean("perfect");
您可以在發送方嘗試此操作:
MyModel model = new MyModel();
//1. using constructor
Boolean blnObj1 = new Boolean(model.getBooleanStatus()); // This //getBooleanStatus will return 'boolean' value
//2. using valueOf method of Boolean class. This is a static method.
Boolean blnObj2 = Boolean.valueOf(model.getBooleanStatus());
}
Intent targetIntent = new Intent(MyCalass.this, TargetClass.class);
targetIntent.putExtra("STATUS", new Boolean(model.getBooleanStatus()));
targetIntent.putExtra("STATUS", Boolean.valueOf(model.getBooleanStatus()));
startActivity(targetIntent);
接收方:
Intent receiverIntent = getIntent().getBoolean("STATUS");
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.