-3

I need a litle guidance about my thoughts on android development. Is it possible to restart my appication on a specific point of my code? I also need to reuse some values that my application derive? I am looking at alarm manager and sharedpreferences... Am I on the right way, to implement that?

BR

Lal
  • 14,726
  • 4
  • 45
  • 70
KostasA
  • 5,204
  • 6
  • 23
  • 29
  • `Intent` your package from where you want to start you activity [link](http://stackoverflow.com/questions/2741857/launch-activities-from-different-package) – Iamat8 Sep 10 '15 at 08:52

2 Answers2

0

Yes you are on right track ,you can restart your android application at any point you want and store your data either in Sharedprefernces if its a small amount of data but if the data is large use Sqlite instead.

AlarmManager will help you in schedule your tasks for future like restart app at specific time etc.

Code for restarting app

Intent intent = getBaseContext().getPackageManager()
         .getLaunchIntentForPackage( getBaseContext().getPackageName() );
intent .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
Ashish Shukla
  • 1,027
  • 16
  • 36
-1
Intent          restartIntent   = getContext().getPackageManager().getLaunchIntentForPackage(getContext().getPackageName());
PendingIntent   pendingIntent   = PendingIntent.getActivity(getContext(), 0, restartIntent, Intent.FLAG_ACTIVITY_CLEAR_TOP);
AlarmManager    alarmManager    = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
alarmManager.set(AlarmManager.RTC, System.currentTimeMillis() + APPLICATION_RESTART_TIMEOUT, pendingIntent);
naXa stands with Ukraine
  • 35,493
  • 19
  • 190
  • 259
Vladimir Eremeev
  • 262
  • 1
  • 10