Working environment (bold blue for special attention)
1, System environment: Win7 Ultimate SP1, Android Studio 3.2
Oddly enough, today when a Bundle is used to pass values between activities, it is not possible to get the value passed in. Look at the pass-value code:
1, System environment: Win7 Ultimate SP1, Android Studio 3.2
Oddly enough, today when a Bundle is used to pass values between activities, it is not possible to get the value passed in. Look at the pass-value code:
Bundle bundle = new Bundle();
bundle.putInt(EXAM_CENTER_TYPE, EXAM_CENTER_1);
toActivity(ExamTypeActivity.class, bundle);
protected void toActivity(Class<?> clazz, Bundle bundle) {
Intent intent = new Intent();
intent.setClass(this, clazz);
if (bundle != null) {
intent.putExtras(bundle);
}
startActivity(intent);
}
Value code:
protected Bundle getExtra() {
Intent intent = getIntent();
if (intent != null) {
return getIntent().getExtras();
} else {
return null;
}
}
protected String getExtraString(String key) {
Bundle bundle = getExtra();
if (bundle != null) {
return bundle.getString(key);
} else {
return "";
}
}
protected int getExtraInt(String key) {
String extra = getExtraString(key);
return NumberUtils.getInt(extra);
}
GetExtraaint (EXAM_CENTER_TYPE) cannot get a value. The reason is that the data type passed to PUT must be the same as that of GET. If you put is a string, get is a string. The getExtraint function can be changed to the following function:
protected int getExtraInt(String key) {
Bundle bundle = getExtra();
if (bundle != null) {
return bundle.getInt(key);
} else {
return 0;
}
}
Read More:
- The reason and solution of Android intent value not updated
- The intent solution cannot be updated in onrestart method
- Javabinder:
- The problem that the content extra data in the notification cannot be updated
- Java gets the type t.class of generic t
- Android: Web access activity error: error unknown URL scheme
- C++:error C2228: left of ‘.str’ must have class/struct/union
- Python: Understanding__ str__
- Common errors and modification methods of findbug
- Unity learning — stop coroutine
- [$ injector:unpr ] Unknown provider:–angular.module () function solution
- Pit encountered by entity class data type BigDecimal
- An error is reported for the new Android project. Rejecting re init on previously failed
- Android android.intent.category Purpose and use of. Launcher
- panic: runtime error: index out of range
- C++ Error: allocating an object of abstract class type
- Difference between isempty method and isblank method in stringutils
- Java String.split () special character processing
- Java encrypts the string with MD5
- How to come a good theoretical physics