|
|
|
@ -1,6 +1,8 @@
|
|
|
|
|
package com.xypower.mpapp;
|
|
|
|
|
|
|
|
|
|
import android.Manifest;
|
|
|
|
|
import android.app.AlarmManager;
|
|
|
|
|
import android.app.PendingIntent;
|
|
|
|
|
import android.content.Context;
|
|
|
|
|
import android.content.DialogInterface;
|
|
|
|
|
import android.content.Intent;
|
|
|
|
@ -18,6 +20,7 @@ import androidx.core.app.ActivityCompat;
|
|
|
|
|
import androidx.appcompat.app.AppCompatActivity;
|
|
|
|
|
|
|
|
|
|
import android.os.Bundle;
|
|
|
|
|
import android.os.SystemClock;
|
|
|
|
|
import android.telephony.SubscriptionManager;
|
|
|
|
|
import android.text.TextUtils;
|
|
|
|
|
import android.util.Log;
|
|
|
|
@ -357,18 +360,46 @@ public class MainActivity extends AppCompatActivity {
|
|
|
|
|
binding.btnRestartApp.setOnClickListener(new View.OnClickListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onClick(View v) {
|
|
|
|
|
restartSelfWithStartActivity();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void restartSelfWithStartActivity() {
|
|
|
|
|
|
|
|
|
|
Context context = MainActivity.this;
|
|
|
|
|
|
|
|
|
|
Intent intent = new Intent(context, MainActivity.class);
|
|
|
|
|
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
|
|
|
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK| Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
|
|
|
|
|
|
|
|
|
int noDelay = 1;
|
|
|
|
|
intent.putExtra("noDelay", noDelay);
|
|
|
|
|
intent.putExtra("reason", "Manual Restart From MainActivity");
|
|
|
|
|
|
|
|
|
|
// finish();
|
|
|
|
|
context.startActivity(intent);
|
|
|
|
|
|
|
|
|
|
finish();
|
|
|
|
|
System.exit(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void restartSelfWithAlarmManager() {
|
|
|
|
|
Intent intent = new Intent(MainActivity.this, MainActivity.class);
|
|
|
|
|
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK| Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
|
|
|
|
|
|
|
|
|
int noDelay = 1;
|
|
|
|
|
intent.putExtra("noDelay", noDelay);
|
|
|
|
|
intent.putExtra("reason", "Manual Restart From MainActivity");
|
|
|
|
|
|
|
|
|
|
// Create PendingIntent
|
|
|
|
|
PendingIntent pendingIntent = PendingIntent.getActivity(
|
|
|
|
|
MainActivity.this, 12312, intent, PendingIntent.FLAG_UPDATE_CURRENT/* | PendingIntent.FLAG_IMMUTABLE*/);
|
|
|
|
|
|
|
|
|
|
AlarmManager alarmManager = (AlarmManager) MainActivity.this.getSystemService(Context.ALARM_SERVICE);
|
|
|
|
|
|
|
|
|
|
if (alarmManager != null) {
|
|
|
|
|
alarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + 200, pendingIntent);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MainActivity.this.finish();
|
|
|
|
|
System.exit(0);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|