Skip to content

App automatically keeps coming in to the foreground after closing in few Devices #36

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
rohitsangwan01 opened this issue Dec 15, 2021 · 8 comments

Comments

@rohitsangwan01
Copy link

Hey , in Few Devices ,App opens automatically
tested in Samsung S8+ ,Android version is 9 ,

auto_foreground.mp4

attached a video of issue , i can't really figure out why this is happening ,
Altough its working fine on my device , One plus 8T ,android V11

@Dev-hwang
Copy link
Owner

It's hard to understand the question. Could you please explain a little more in detail?

@rohitsangwan01
Copy link
Author

Okk, when app opens , am starting Foreground services , without callbacks and StickyNotification:false , and After that am starting Bluetooth Scan , Now when user minimise the app by pressing Home Button,. bluetooth device scanning is still in progress in the App
And After some time App automatically Opens , Attached a Video above , checkout for better understanding , Am not sure why getting this behaviour while Bluetooth Scanning Only,. And till now only that specific device reported that Issue (Samsung S8+)

@Dev-hwang
Copy link
Owner

That's weird. This plugin does not have the ability to force the app to launch or open it.

Is this a problem with this plugin? Can you try removing the WithForegroundTask widget just in case? If this doesn't work, you need to test if the problem is caused by using this plugin.

@rohitsangwan01
Copy link
Author

am not using WithForegroundTask Widget , thats my code for starting Foreground task from splash screen

 Future<void> StratAndroidBackground() 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,
        isSticky: false,
        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: true,
        playSound: false,
      ),
      foregroundTaskOptions: const ForegroundTaskOptions(
        interval: 5000,
        autoRunOnBoot: false,
        allowWifiLock: false,
      ),
      printDevLog: true,
    );

    ///Check If Background Service is already running

    bool isIgnoringBatteryOptimisations =
        await FlutterForegroundTask.isIgnoringBatteryOptimizations;

    if (!isIgnoringBatteryOptimisations) {
      await FlutterForegroundTask.requestIgnoreBatteryOptimization();
    }

    bool isRunning = await FlutterForegroundTask.isRunningService;

    if (isRunning) return;
    await FlutterForegroundTask.startService(
      notificationTitle: "Service is running in background",
      notificationText: "Tap to open",
      //  callback: startCallback,
    );
  }

can it be something related to Samsung device , because am not facing such issue in my Device on Stock android

@Dev-hwang
Copy link
Owner

I'm new to this too, so I don't know why it's causing the problem.

One guess is that searching for Bluetooth is the cause. Would you like to test by turning off the Bluetooth scan function for a while?

@Dev-hwang
Copy link
Owner

There doesn't seem to be any problems with setting up and starting the foreground service.

@rohitsangwan01
Copy link
Author

Okk Thanks , will try to check what exactly causing this issue

@rohitsangwan01
Copy link
Author

@Dev-hwang ,finally fixed it , actually in few device ,while scanning , i was checking if bluetooth is on or not , and when that native call happens for checking , app auto came to foreground in few devices , altough am not sure why this was happening but modifying that bluetooth check code fix the problem

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