Activity on background

Hello,
What is the reason for following activity while App on Background?
And showLogs = false

Mobile device
Redmi 10C connecting to Android Studio
MIUI Global 14.0.3
amity_sdk: 0.26.0

Setup code

var v = await AmityCoreClient.setup(
  option: AmityCoreClientOption(
      apiKey: apiKey,
      httpEndpoint: AmityRegionalHttpEndpoint.EU,
      socketEndpoint: AmityRegionalSocketEndpoint.EU,
      mqttEndpoint: AmityRegionalMqttEndpoint.EU,
      showLogs: false),
  sycInitialization: true,
);

Log
D/DecorView: onWindowFocusChanged hasWindowFocus true
I/HandWritingStubImpl(20372): refreshLastKeyboardType: 1
I/HandWritingStubImpl(20372): getCurrentKeyboardType: 1
D/DecorView: onWindowFocusChanged hasWindowFocus false
[log] AMITY_MQTT::Ping response client callback invoked
[log] AMITY_MQTT::Ping response client callback invoked
D/TrafficStats(20372): tagSocket(87) with statsTag=0xffffffff, statsUid=-1
D/TrafficStats(20372): tagSocket(87) with statsTag=0xffffffff, statsUid=-1
[log] AMITY_MQTT::Ping response client callback invoked
[log] AMITY_MQTT::Ping response client callback invoked
[log] AMITY_MQTT::Ping response client callback invoked

Hi @meridork ,

This seems to notify the server that the user is still online until app sleep.

Is there an issue you’re facing with it?

Thank you,
Amity Support

Sometimes I have crashes on iPhone when the App on background.
Why to notify server when App in background?
Is it possible not notify the server while App in background?
Thanks, Kobi

Hi @meridork

Can you please help share details of the crash?

  1. which platform & version (did you recently upgrade?)
  2. steps to reproduce : eg does it happen only when app’s in background? what did you do before that? are there specific tasks done while app’s in background
  3. screenshots & sample codes

So we can help investigate and solve this. It’s not confirmed if this is due the this notification or not yet.

Thank you,
Amity Support

Hi
The crashes are on my iPhone
I’m on main screen displaying the Feed in static mode no refreshing
Attached
Move the App to background sometimes open another App.
While the App on background I will have the crash.
iPhone 14 pro max with 16.6
The App don’t have tasks while on background

The log in this case are from my Android that connecting to my PC and working with android studio. The activity that in the log start after theApp going to background. I don’t understand why this is happening while on backpacking mode

Could you please confirm if this crash is specific to iOS? Additionally, could you let us know how long you left it in background mode before the crash occurred?

Hey @meridork can we confirm one thing, you mentioned that ‘The log in this case are from my Android that connecting to my PC and working with android studio.’ - we understand that this issue is happening on ios, can we get the log from ios as well? It is working fine on android, correct?

Hello

It’s working ok an Android

I don’t have Mac to work with iPhone to get the logs
Kobi

Hello @meridork we cannot replicate the crash on our side, but to provide answer to your question about the log and activity/background mode area:

This logs [log] AMITY_MQTT::Ping response client callback invoked you get in the background state are from MQTT , to keep the connection alive even when the app is in background, For example if someone deletes or updates the message while you are in background, you will get the latest data when you get back to the application.

We will try to reproduce and dig deeper into this. If we come across any potential issues, we’ll let you know.

I think we don’t have to update the Feed while device in background.
We can update the Feed while coming back to foreground.
Working on background in iPhone could be a problem
Can I stop updating while device on background?

Kobi

Hi @meridork Currently, manual termination of the MQTT connection is not supported in our SDK. The connection will only be terminated when the user logs out from the application or forcefully closes the app.

We attempted to reproduce the issue using the same version as yours, but unfortunately, we couldn’t replicate it. Our team has shared the sample code below for your reference.


import 'dart:developer';

import 'package:amity_sdk/amity_sdk.dart';
import 'package:flutter/material.dart';

import '../../components/alert_dialog.dart';

enum Feedtype { global, commu }

class FeedVM extends ChangeNotifier {
  var _amityGlobalFeedPosts = <AmityPost>[];

  late PagingController<AmityPost> _controllerGlobal;

  final scrollcontroller = ScrollController();

  bool loadingNexPage = false;
  List<AmityPost> getAmityPosts() {
    return _amityGlobalFeedPosts;
  }

  Future<void> addPostToFeed(AmityPost post) async {
    _controllerGlobal.addAtIndex(0, post);
    notifyListeners();
  }

  void deletePost(AmityPost post, int postIndex) async {
    AmitySocialClient.newPostRepository()
        .deletePost(postId: post.postId!)
        .then((value) {
      _amityGlobalFeedPosts.removeAt(postIndex);
      notifyListeners();
    }).onError((error, stackTrace) async {
      await AmityDialog()
          .showAlertErrorDialog(title: "Error!", message: error.toString());
    });
  }

  Future<void> initAmityGlobalfeed() async {
    _controllerGlobal = PagingController(
      pageFuture: (token) => AmitySocialClient.newFeedRepository()
          .getGlobalFeed()
          .getPagingData(token: token, limit: 5),
      pageSize: 5,
    )..addListener(
        () async {
          log("initAmityGlobalfeed listener...");
          if (_controllerGlobal.error == null) {
            _amityGlobalFeedPosts.clear();
            _amityGlobalFeedPosts.addAll(_controllerGlobal.loadedItems);

            notifyListeners();
          } else {
            //Error on pagination controller

            log("error");
            await AmityDialog().showAlertErrorDialog(
                title: "Error!", message: _controllerGlobal.error.toString());
          }
        },
      );

    WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
      _controllerGlobal.fetchNextPage();
    });
    scrollcontroller.removeListener(() {});
    scrollcontroller.addListener(loadnextpage);

    // //inititate the PagingController
    // await AmitySocialClient.newFeedRepository()
    //     .getGlobalFeed()
    //     .getPagingData()
    //     .then((value) async {
    //   _amityGlobalFeedPosts = value.data;
    //   if (_amityGlobalFeedPosts.isEmpty) {
    //     await AmityDialog().showAlertErrorDialog(
    //         title: "No Post yet!",
    //         message: "please join some community or follow some user 🥳");
    //   }
    // }).onError(
    //   (error, stackTrace) async {
    //     await AmityDialog()
    //         .showAlertErrorDialog(title: "Error!", message: error.toString());
    //   },
    // );
    // notifyListeners();
  }

  void loadnextpage() async {
    // log(scrollcontroller.offset);
    if ((scrollcontroller.position.pixels >
            scrollcontroller.position.maxScrollExtent - 800) &&
        _controllerGlobal.hasMoreItems &&
        !loadingNexPage) {
      loadingNexPage = true;
      notifyListeners();
      log("loading Next Page...");
      await _controllerGlobal.fetchNextPage().then((value) {
        loadingNexPage = false;
        notifyListeners();
      });
    }
  }
}

Thanks I will check it soon
Kobi

Thanks
I implemented the code specialty the initAmityGlobalfeed
and define the services as ChangeNotifier

I will check for any problems in following days

1 Like

Thanks for the updates, looking forward to hearing the feedback from you.

1 Like