mirror of
https://github.com/lollipopkit/flutter_server_box.git
synced 2025-12-17 23:34:24 +01:00
#139 fix
This commit is contained in:
@@ -55,5 +55,7 @@
|
||||
android:name="android.appwidget.provider"
|
||||
android:resource="@xml/home_widget" />
|
||||
</receiver>
|
||||
|
||||
<service android:name=".KeepAliveService"/>
|
||||
</application>
|
||||
</manifest>
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
package tech.lolli.toolbox
|
||||
|
||||
import android.app.Service
|
||||
import android.content.Intent
|
||||
|
||||
import android.os.IBinder
|
||||
import org.jetbrains.annotations.Nullable
|
||||
|
||||
class KeepAliveService : Service() {
|
||||
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
|
||||
return START_STICKY
|
||||
}
|
||||
|
||||
@Nullable
|
||||
override fun onBind(intent: Intent?): IBinder? {
|
||||
return null
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package tech.lolli.toolbox
|
||||
|
||||
import android.content.Intent
|
||||
import io.flutter.embedding.android.FlutterActivity
|
||||
import io.flutter.embedding.engine.FlutterEngine
|
||||
import io.flutter.plugin.common.MethodChannel
|
||||
@@ -11,11 +12,18 @@ class MainActivity : FlutterActivity() {
|
||||
|
||||
MethodChannel(binaryMessenger, "tech.lolli.toolbox/app_retain").apply {
|
||||
setMethodCallHandler { method, result ->
|
||||
if (method.method == "sendToBackground") {
|
||||
moveTaskToBack(true)
|
||||
result.success(null)
|
||||
} else {
|
||||
result.notImplemented()
|
||||
when (method.method) {
|
||||
"sendToBackground" -> {
|
||||
moveTaskToBack(true)
|
||||
result.success(null)
|
||||
}
|
||||
"startService" -> {
|
||||
val intent = Intent(this@MainActivity, KeepAliveService::class.java)
|
||||
startService(intent)
|
||||
}
|
||||
else -> {
|
||||
result.notImplemented()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user