Search code examples
androidandroid-activitysdk

On Finish activity in Android


Im trying to integrate Tapresearch survey in my android app. The company provides an SDK. The SDK gives the ability to use events listeners. One of the listeners doesn't work which is onSurveyModalClosed()` where normally the app resumes running. All other listeners works fine except this one. When Tapresearch open surveys it runs this activity : com.tapr.internal.activities.survey.SurveyActivity .

Is there any way check if this activity has been finished without using the listener onSurveyModalClosed() ?


Solution

  • For your question, "is there any way check if this activity has been finished without using the listener", yes there is a way.

    Just put a Log message in both the methods. And see which Log message is printed in the console or which is printed first and take actions accordingly.

    @Override
    public void onSurveyModalClosed() {
       //Survey isn't visible resume app
       Log.i("Sequence_of_execution", "SurveyModalClosed");
    }
    
    @Override
    protected void onStop() {
       super.onStop();
       // Your code goes here
       Log.i("Sequence_of_execution", "ActivityStopped");
    }
    

    I guess onSurveyModalClosed() is called when you manually close the survey by taking any action and not when the Activity stops.

    And for your question in comments to check if you are coming from SurveyActivity to MainActivity, do this since you don't have control over SurveyActivity-

    1. Declare a shared preferences variable called "SurveyActivityStarted" in MainActivity and set it to false.
    2. When starting the SurveyActivity from MainActivity, set "SurveyActivityStarted" to true.
    3. on onResume of the MainActivity check if "SurveyActivityStarted" is true, if its true its coming from SurveyActivity.
    4. Reinitialise "SurveyActivityStarted" to false in the MainActivity for future use cases.