2

I have an android device, which runs my app as system app. In this app there is an update function, which download the new version of the apk from the internet and then overwrites the apk on the device. After that I need to restart the application... and this is my problem, I have tried many ways:

finish();

Intent i = getBaseContext().getPackageManager().getLaunchIntentForPackage(getBaseContext().getPackageName() );   
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK );
startActivity(i);

System.exit();

android.os.Process.killProcess(pid);

I noticed that if I stop the system_process in Eclipse, my devices is restarting, app is upgrading and the new version of my app is running. So my question is, how can I stop/restart system_process programmatically? Or have you got any good idea to restart and run my new versioned app? Thx :)

  • try this link http://stackoverflow.com/questions/2486934/programmatically-relaunch-recreate-an-activity – TechArcSri Sep 10 '14 at 06:45
  • chnage this android.os.Process.killProcess(pid) to --->android.os.Process.killProcess(android.os.Process.myPid()); – KOTIOS Sep 10 '14 at 06:47
  • Hello. If I kill my app with killProcess, it goes in a dead loop... ActivityManager kills the process then stars, but it throws NullPointerException, and dies again... – Botond Kelés Sep 10 '14 at 07:08

1 Answers1

2

Thx. It does the magic! :)

PowerManager pm = (PowerManager) this.getApplicationContext().getSystemService(Context.POWER_SERVICE);
pm.reboot("bootloader");