Skip to content

Issue with activityLifecycleCallbacks if the Capture initialized on demand #2

@salim-lachdhaf

Description

@salim-lachdhaf

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions