I have to retrieve the total number of permits required by the application, and store this value for use in a second Activity, but without letting it open with the intent. I wrote this code.
try {
PackageInfo packageInfo = getActivity().getPackageManager().getPackageInfo(value2, PackageManager.GET_PERMISSIONS);
String[] requestedPermissions = packageInfo.requestedPermissions;
if ( requestedPermissions != null ) {
for ( i = 0; i < requestedPermissions.length; i++) {
permissions.append(requestedPermissions[i]+"\n");
int total = i++;
Intent intent = new Intent();
intent.putExtra("totalPermissions",total);
}
}
}
catch ( PackageManager.NameNotFoundException e ) {
e.printStackTrace();
}
In another PreferenceActivity
Bundle extras = getIntent().getExtras();
if(extras!=null) {
int tot = extras.getInt("totalPermissions");
permissionsPreference.setSummary(""+tot);
In the Summary of Prefence return 0. Why? Where is the error?
您在使用价值并从意图中获取价值时使用了不同的键,这就是为什么您获得零的原因。
The two intent are not the same one. You can make a public static int total;
Modify its value in the first activity, and get its value in the second activity by FirstActivity.total
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.