Closed Luklek closed 6 years ago
the startActivityForResult
will only create one instance. Probably the function is called twice?
Can't reproduce anymore.
Actually it happened again just now... I had added a log in onConsentNeedsToBeRequested and it's called twice.
Where do you call GDPR.getInstance().checkIfNeedsToBeShown(...)
from? Make a log before this one as well and check if this is called twice... I don't see any way that this happens if it is not called twice as well
Yes, you are right.
I am calling GDPR.getInstance().checkIfNeedsToBeShown(...)
onCreate and the Log onCreate was called twice too.
I would suggest following:
@Override
public void onCreate(Bundle savedInstanceState) {
...
GDPR.getInstance().checkIfNeedsToBeShown(...)
...
}
@Override
public void onDestroy() {
...
GDPR.getInstance().cancelRunningTasks();
...
}
If you use a dialog, this is not necessary, because the dialog only shows itself if it is not created already, even after activity recreation... The activity does not have this.
The best would be to cancel the task that checks the location in the onDestroy
event, so you are save to just check it again whenever the activity is created again...
You mean to add GDPR.getInstance().cancelRunningTasks();
onCreate of the "DemoGDPRActivity"?
I also added android:launchMode = "singleInstance"
in Manifest of my main activity as I found some reports of onCreate called 2 times on Samsung phones (which I am using for testing too)
Should work as well...
I will additionally check the activity.isFinishing()
in the next update before the async task will emit it's result to the activity...
Still, in an activity it makes sense to manually cancel the task (I would still suggest in onDestroy
)
OK.
I updated to latest snapshot with the activity.isFinishing()
and also added
@Override
public void onDestroy() {
GDPR.getInstance().cancelRunningTasks();
Timber.d("onDestroy");
super.onDestroy();
}
but the DialogActivity is launched a second time anyway. (it happens in very rare case)
E/RealSplashActivity:57: GDPR Consent = UNKNOWN E/GDPRDemo [GDPR]: consent check needed: true, current consent: { Consent: UNKNOWN | Location: UNDEFINED | Date: Jan 1, 1970 07:00:00 | Version: 0} E/GDPRDemo [PreperationAsyncTask]: GDPRPreperationData: { Location: UNDEFINED | SubNetworks: 0 | Error: false } E/RealSplashActivity:126: GDPR onConsentNeedsToBeRequested D/RealSplashActivity:108: onDestroy E/RealSplashActivity:57: GDPR Consent = UNKNOWN E/GDPRDemo [GDPR]: consent check needed: true, current consent: { Consent: UNKNOWN | Location: UNDEFINED | Date: Jan 1, 1970 07:00:00 | Version: 0} E/GDPRDemo [PreperationAsyncTask]: GDPRPreperationData: { Location: UNDEFINED | SubNetworks: 0 | Error: false } E/RealSplashActivity:126: GDPR onConsentNeedsToBeRequested
If you have two activities, they of course each have their own AsyncTask
... you must find out why the RealSplashActivity
is created twice... I don't know whiy this happens, sorry
What you mean that I have 2 activities? just the RealSplashActivity
Anyway I guess I will use the BottomSheet dialog to make sure.
your RealSplashActivity
s onCreate
is called twice, isn't it?
Yes, that's why GDPR.getInstance().checkIfNeedsToBeShown(...)
is called 2 times too, as you suggested it may be the case before (otherwise I may have not noticed that^^)
Anyway using BottomSheet the dialog is created only 1 time, so I think I will use that instead.
Sometime the
DemoGDPRActivity.startActivityForResult(this, mSetup, data.getLocation(), DemoGDPRActivity.class, DEMO_GDPR_ACTIVITY_REQUEST_CODE);
creates 2 activities on top of each other. After clicking on the first, the second is displayed and need to click again on consent.Any idea on how I could track/check or reproduce this?