update My App Issue

android, android-intent, broadcastreceiver

Solution

unfortunately you can't prevent process from been terminated when it re-install itself, and from the other hand - you'll never receive any broadcast if it your own app that been re-install at that time.

if I had to implement such feature, I would solve the problem like this:

trick number 1:

creating another app (that would be installed somehow also on your user's device) that it only roll is to act like sort of a "watch-dog": this app would listen to installation broadcasts, and because it's different app then the one who been installed - it won't have problem to launch to "original app".

of-course don't forget that the user will need to "launch" at least ones this watch-dog app, because from android 4 receivers won't work until the app process started at least ones from. that is for security reasons..

trick number 2:

another option would be to registered in manifest you app also to `ACTION_TIME_TICK` broadcast. you can count on this broadcast to be called each number of seconds, and implement when it receives some logic that recognize if the app right now need to launch the main activity or not.

this approach will work, but from performances reason would be not that good - because you app process would be alive almost all the time because it reacts to that broadcast. if you don't care about that - so it not problem

trick number 3:

provide `pendingIntent` to `alarmManager` just before you start the installation activity to a 30-50 seconds after. the pending intent will hold intent to re-launch your app.

assuming the app would be installed until then - it would work.

Problem

I'm developing a non-public Android app, i.e. the app won't be available in the global Android Market. The app will be installed on a limited number of clients, e.g. by using an apk file.I Have an .apk in SD Card and I am trying to update my application from my application. For that, I'm Using Intent My Code ``` Intent intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(Uri.fromFile(new File(Environment.getExternalStorageDirectory().getPath()+"/" +"Test.apk")), "application/vnd.android.package-archive"); startActivity(intent); ``` NOTE : It is working fine, but after updating it, application will be closed. The question is "How to Prevent This ?" I'm also use Broadcast Receiver For Re-Open my app ``` public class AutoStart extends BroadcastReceiver{ @Override public void onReceive(Context context, Intent intent) { if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)){ Intent i = new Intent(context, ABCActivity.class); i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(i); }else{ Intent i = new Intent(context, XYZActivity.class); i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(i); } } ``` Problem 1 :- Can't Re-Open Activity When "android.intent.action.PACKAGE_ADDED", "android.intent.action.PACKAGE_INSTALL", "android.intent.action.PACKAGE_CHANGED" ``` <receiver android:name=".AutoStart" android:enabled="true" android:exported="true" > <intent-filter android:priority="100" > <action android:name="android.intent.action.BOOT_COMPLETED" /> </intent-filter> <intent-filter> <action android:name="android.intent.action.PACKAGE_ADDED" /> <data android:scheme="package" /> </intent-filter> <intent-filter> <action android:name="android.intent.action.PACKAGE_INSTALL" /> <data android:scheme="package" /> </intent-filter> <intent-filter> <action android:name="android.intent.action.PACKAGE_CHANGED" /> <data android:scheme="package" /> </intent-filter> <intent-filter> <action android:name="android.intent.action.PACKAGE_REPLACED" /> <data android:scheme="package" /> </intent-filter> </receiver> ``` "android.intent.action.BOOT_COMPLETED" Working Properly Permissions Given ``` 1 > <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> 2 > <uses-permission android:name="android.permission.RESTART_PACKAGES" /> 3 > <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> ```

Original source

Related problems