How to restart an application completely?

前端 未结 7 1570
长发绾君心
长发绾君心 2021-01-04 17:35

I have an application which starts a Remote Service in its first launched activity. Then, in another activity, the user can set the configuration of the application. Please

7条回答
  •  春和景丽
    2021-01-04 18:28

    By Using a Pending Intent You can Restart your Application when you want,Just use the below Lines of code

    int pendingId_Intent = 987654;
    Intent YourMainActivityIntent = new Intent(Context, YourMainActivity.class);
    
    PendingIntent intentPending = PendingIntent.getActivity(context, 
    pendingId_Intent,    YourMainActivityIntent, 
    PendingIntent.FLAG_CANCEL_CURRENT);
    AlarmManager alarm_manager = 
    (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
    alarm_manager.set(AlarmManager.RTC, System.currentTimeMillis() + 100, 
    intentPending);
    System.exit(0);
    

提交回复
热议问题