Skip to content
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

Issue with activityLifecycleCallbacks if the Capture initialized on demand #2

Open
salim-lachdhaf opened this issue Dec 7, 2022 · 0 comments

Comments

@salim-lachdhaf
Copy link

salim-lachdhaf commented Dec 7, 2022

the issue is reproductible in the following scenario:
Let's say we have two Activities A and B.
The user wants initialize the Capture ONLY on demand, in this case for example we add a button that handle Capture.init in the activity A (till now everything OK).

note = until now in the CaptureActivityLifecycleCallbacks, the activityCount = 0

Now we navigate from the activity A to Activity B

  • onActivityStarted (B) will be called (activityCount == 0 => FOREGROUND ; activityCount ++ => activityCount =1 => Capture connect )
  • onActivityStopped (A) will be called after ( activityCount -- => activityCount = 0 ; BACKGROUND => Capture Disconnect)

As we see here, once we are in B activity, the state of Capture is Disconnected !

class ActivityA : AppCompatActivity() {
    .....
    override fun onCreate(savedInstanceState: Bundle?) {
         .....

        binding.initSocket.setOnClickListener {
                Capture.builder(getApplicationContext())
                            .enableLogging(BuildConfig.DEBUG)
                            .build()
               Capture.connect{}
      }

        binding.goToB.setOnClickListener {
            //till now every thing works fine
            startActivity(Intent(this, ActivityB::class.java))
        }
    }
}
class ActivityB : AppCompatActivity() {
    .....
   
   //my Capture is  not connected any more , even if we go back to ActivityA
   
}

As solution for this issue, i think it will be better to add in CaptureActivityLifecycleCallbacks class a List of started activities , and we change visibility to gone only the already started activities... In resume we stop only started activities.
Or add some method to increment activityCount manually

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

1 participant