What is sharedUserId in Android, and how is it used?
Solution 1
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.
Solution 2
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>
Bhargav Panchal
Updated on March 09, 2020Comments
-
Bhargav Panchal over 4 years
I am confused in sharedUserID.what is use of sharedUserId?How to use?Where to use in android?
-
njzk2 over 12 yearsan important addition is that you can only install two applications with the same shareduserid is both the applications were signed with the same certificate.
-
Piyush Agarwal almost 11 yearsHow many applications can have same sharedUserId in a device? If I am having five applications with same userId in a device will it affect the applications performance as they are running in same process ?
-
IgorGanapolsky over 10 yearsHow do you modify Android.mk? I haven't seen any references to it informing us on what that file is all about...
-
Lo-Tan about 10 years@pyus13 I don't believe they are forced to run in the same process. That is just an option if you desire to do so.
-
Piyush Agarwal about 10 yearsI have shared user id in many of my apps to share private preferences. The surprising thing is they works fine if I have targetSDK version 9 but if i have targetSK version 14 it stopped working.
-
Hartok over 9 years@IgorGanapolsky Android.mk is a makefile for Android NDK (C/C++). If your app uses Java only, you don't have one.
-
Hartok over 9 yearsWorks fine for me (target API 21) with at least 3 apps sharing the same UserId.
-
RocketRandom about 8 yearsThat is incorrect. This file is required for ALL applications which are to be built as part of AOSP. Including java only ones.
-
The Dude about 7 yearsNo its not necessary to set the mk file
-
Prudhvi over 4 yearsFrom Android documentation, "Shared user IDs cause non-deterministic behavior within the package manager. As such, its use is strongly discouraged and may be removed in a future version of Android. Instead, apps should use proper communication mechanisms, such as services and content providers, to facilitate interoperability between shared components."