Reputation: 31479
In the AndroidManifest
file of my application, the main Activity
's android:name
has always been:
android:name=".MainActivity"
Recently, I have changed the app to use a library. All the code has been transferred to the library project so that I can offer a free and a paid version, both using the same code (except to some modifications).
Now the name of the main Activity
in the manifest file is:
android:name="com.name.library.MainActivity"
Unfortunately, users are reporting now that they cannot open the updated app anymore on their phone. Android says: App not installed!
After some searching, I found the cause for this problem here: You cannot change an Activity
's name without causing problems for other apps trying to use Intent
s for this app. I guess the users who report the problem have placed my app on their home screen and the launcher application doesn't find the old Activity
name anymore. Is that true?
But does this also affect the menu with all apps listed? Actually, Android should update the Activity
's name on update, shouldn't it?
And how to resolve this problem? My only idea is to create a new Activity
with the old name and in onCreate(...)
, place the following code:
Intent i = new Intent(MainActivity.this, MainActivity.class);
i.setComponentName("com.app.library", "com.app.library.MainActivity);
startActivity(i);
But this is not a pleasant solution, obviously ...
Upvotes: 2
Views: 1453
Reputation: 24820
I guess you could also use an activity-alias .
<activity-alias
android:targetActivity="com.name.library.MainActivity"
android:name=".MainActivity"
android:label="@string/label"
android:icon="@drawable/icon">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
</intent-filter>
</activity-alias>
android:name should match the old activity name
Upvotes: 3
Reputation: 3602
i think you have made your changes in a wrong way. You don't have so many choises: since the moment the user puts a shortcut to your app on his homescreen, the shorcut refers to a specific uri (you.old.package.MainActivity) and i think the only thing you can do is what you said, even if is not a pleasant solution. The other solution is that the users delete and recreate the shortcut to your app, since the moment that when an application changes it-s internal structure, the intent which is launched is always the one with the intent filters
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
declared in the manifest; so re-creating the shortcut will fix the problem.
You should have made the changes in order to let the old project to become the library project, and create the Lite and Pro projects to use the original project became a libray project. In this way the uri of your activity did not need to be changed
Upvotes: 2