Skip to content

how to prevent android from kill my app #33

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
AbanoubWagih94 opened this issue Dec 8, 2021 · 6 comments
Closed

how to prevent android from kill my app #33

AbanoubWagih94 opened this issue Dec 8, 2021 · 6 comments

Comments

@AbanoubWagih94
Copy link

AbanoubWagih94 commented Dec 8, 2021

i have audio app its job play audio in background and when screen look.
i have one problem that android os kill my app after 1hour or less .
now i used you package from prevent os from kill app but still kill it.
and when on lock screen didn't go to next track until open screen
my code

 @override
  void initState() {
    super.initState();
    initPlatformState();
    _initForegroundTask();
    _timerLink = new Timer(
      const Duration(milliseconds: 3000),
      () {
        _dynamicLinkService.retrieveDynamicLink(context);
      },
    );
  }
  Future<void> _initForegroundTask() async {
  await FlutterForegroundTask.init(
    androidNotificationOptions: AndroidNotificationOptions(
      channelId: 'notification_channel_id',
      channelName: 'Foreground Notification',
      channelDescription: 'This notification appears when the foreground service is running.',
      channelImportance: NotificationChannelImportance.LOW,
      priority: NotificationPriority.LOW,
      iconData: const NotificationIconData(
        resType: ResourceType.mipmap,
        resPrefix: ResourcePrefix.ic,
        name: 'launcher',
      ),
      buttons: [
        const NotificationButton(id: 'sendButton', text: 'Send'),
        const NotificationButton(id: 'testButton', text: 'Test'),
      ],
    ),
    iosNotificationOptions: const IOSNotificationOptions(
      showNotification: false,
      playSound: false,
    ),
    foregroundTaskOptions: const ForegroundTaskOptions(
      interval: 5000,
      autoRunOnBoot: false,
      allowWifiLock: true,
    ),
    printDevLog: true,
  );
}

and add WithForegroundTask like that

return Consumer<ThemeProvider>(builder: (context, theme, child) {
      return WithForegroundTask(
        child: GetMaterialApp(
          translations: Translation(),
          debugShowCheckedModeBanner: false,
          theme: lightThemeData(),
          darkTheme: darkThemeData(),
          themeMode: theme.darkMode ? ThemeMode.dark : ThemeMode.light,
          locale: !theme.lang ? Locale('ar') : Locale('en'),
          fallbackLocale: Locale('ar'),
          initialRoute: SplashScreen.routeName,
          routes: routes,
          onGenerateRoute: (RouteSettings routesSettings) {
            final List<String> args = routesSettings.name.split('/');
            if (args[0] != '') {
              return null;
            }
            if (args[1] == 'book') {
              print('hey');
            }
            return;
          },
          onUnknownRoute: (RouteSettings settings) {
            print('bye');
            return;
          },
        ),
      );
    });

all i want to prevent android from kill my app

@AbanoubWagih94
Copy link
Author

Dev-hwang any help please!

@Dev-hwang
Copy link
Owner

Dev-hwang commented Dec 9, 2021

I don't think it's advisable to use this plugin to implement audio apps. This plugin simply provides the ability to perform repetitive tasks in the background. Notifications should also be implemented for audio and music players. Why not try implementing your app using the just_audio plugin?

@AbanoubWagih94
Copy link
Author

AbanoubWagih94 commented Dec 9, 2021

@Dev-hwang
My app work fine but my only problem is android kill it after certain time .
can you tell me how to disable notification from display on notification bar?!

@Dev-hwang
Copy link
Owner

It seems that you need to figure out exactly why the app is shutting down through debugging. You will have to check if the plugin is crashing while running or if the Android system is blocking the app.

The notification could not be removed. To start the foreground service according to the Android platform's policy, must create a notification.

@Dev-hwang
Copy link
Owner

It doesn't seem to have anything to do with the audio app, but it's a good reference.

https://developer.android.com/training/monitoring-device-state/doze-standby

@AbanoubWagih94
Copy link
Author

thanks for your help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants