Issue
I have created an android application. I am trying to call a PinLoginActivity
every time when the user comes from background to foreground. I am using the below method to detect the onStart
and onStop
of all the activities in my application and its working perfectly fine.
class YourApplication : Application() {
override fun onCreate() {
super.onCreate()
registerActivityLifecycleCallbacks(AppLifecycleTracker())
}
}
class AppLifecycleTracker : Application.ActivityLifecycleCallbacks {
private var numStarted = 0
override fun onActivityStarted(activity: Activity?) {
if (numStarted == 0) {
Intent intent = new Intent(getApplicationContext(), PinLoginActivity.class);
intent.putExtra("LockScreen", true);
startActivity(intent);
}
numStarted++
}
override fun onActivityStopped(activity: Activity?) {
numStarted--
if (numStarted == 0) {
}
}
}
Now the problem is:
I am accessing gallery from within my app. Once I open the gallery, select image and comes back to my app. I am getting the PinLoginActivity
. How can I avoid calling the PinLoginActivity
to be called in this scenario ?
Solution
This sample is how you can set a flag in Application and check if the gallery is about to open
public class Application extends android.app.Application {
static boolean isGallery;
@Override
public void onCreate() {
super.onCreate();
}
public static void setGalleryFlag(boolean isTrue){
isGallery = isTrue;
}
public void checkGallery(){
if (isGallery){
//hide your activity
}else{
//operate normally
}
}
}
so when you about to open the gallery just set the flag to true
private void startGallery() {
Application.setGalleryFlag(true);
//open the gallery now
}
Answered By - vikas kumar
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.