What is sharedUserId in Android, and how is it used?

JavaAndroidAndroid IntentAndroid EmulatorAndroid Ndk

Java Problem Overview


I am confused in sharedUserID.what is use of sharedUserId?How to use?Where to use in android?

Java Solutions


Solution 1 - Java

By default, Android assigns a user id to an application. It is the unique id for your application and means that nobody except the user with this id can reach your application's resources. You cannot access the data of an other application or run it in your current process. when, from an activity, an activity of another application is called android passes the control to the new activity called and they run in totally different processes.

However, in your manifest file, you can explicitly identify a user id for your application. When you declare the same user id for more than one application, they can reach each other's resources (data fields, views, etc.). You can display data from another application or run it in your process.

this is how you use it: from http://developer.android.com/guide/topics/manifest/manifest-element.html

    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="string"
    android:sharedUserId="string"
    android:sharedUserLabel="string resource" 
    android:versionCode="integer"
    android:versionName="string"
    android:installLocation=["auto" | "internalOnly" | "preferExternal"] >
    . . .</manifest>

Solution 2 - Java

SharedUserId is used to share the data,processes etc between two or more applications. It is defined in AndroidManifest.xml like,

<manifest
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:sharedUserId="android.uid.shared"
    android:sharedUserLabel="@string/sharedUserLabel"
    ...>

and define the shared parameter in Android.mk for that app, like

LOCAL_CERTIFICATE := shared

Hope its helpful to you.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionBhargav PanchalView Question on Stackoverflow
Solution 1 - JavacaglaView Answer on Stackoverflow
Solution 2 - JavaParthrajView Answer on Stackoverflow