I can't bring the app to the foreground.
I tried to create the following service:
import android.app.Service
import android.content.Intent
import android.os.IBinder
import android.util.Log
class ForegroundService : Service() {
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
Log.d(TAG, "ForegroundService started")
val intent = Intent(this, MainActivity::class.java)
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
startActivity(intent)
stopSelf()
return START_NOT_STICKY
}
override fun onBind(intent: Intent?): IBinder? {
return null
}
companion object {
private const val TAG = "ForegroundService"
}
}
and after that I created the package and instance in MainActivity.kt
Finally in the firebase function, I tried calling the native module
messaging().setBackgroundMessageHandler(async remoteMessage => {
NativeModules.ForegroundServiceModule.startForegroundService();
}
});
}
but nothing happens, I notice that in the application stack, it takes the first position, but it has not yet taken the foreground
Application takes center stage