Use recreate() to recreae Main Activity after restart by Android

This commit is contained in:
Juha Heinanen
2022-02-18 09:18:09 +02:00
parent a112cbbb22
commit 4f7278e3d7
2 changed files with 3 additions and 5 deletions
@@ -315,14 +315,14 @@ class BaresipService: Service() {
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
val action: String? val action: String
if (intent == null) { if (intent == null) {
action = "Start" action = "Start"
Log.d(TAG, "Received onStartCommand with null intent") Log.d(TAG, "Received onStartCommand with null intent")
} else { } else {
// Utils.dumpIntent(intent) // Utils.dumpIntent(intent)
action = intent.action action = intent.action!!
Log.d(TAG, "Received onStartCommand action $action") Log.d(TAG, "Received onStartCommand action $action")
} }
@@ -927,9 +927,7 @@ class MainActivity : AppCompatActivity() {
Log.d(TAG, "Handling service event 'started' with '$callActionUri'") Log.d(TAG, "Handling service event 'started' with '$callActionUri'")
if (!this::uaAdapter.isInitialized) { if (!this::uaAdapter.isInitialized) {
// Android has restarted baresip when permission has been denied in app settings // Android has restarted baresip when permission has been denied in app settings
val i = Intent(this, MainActivity::class.java) recreate()
i.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
startActivity(i)
return return
} }
uaAdapter.notifyDataSetChanged() uaAdapter.notifyDataSetChanged()