Skip to content

Instantly share code, notes, and snippets.

🐢
Just being lazy and crazy

Henry thsaravana

🐢
Just being lazy and crazy
View GitHub Profile
@thsaravana
thsaravana / MyApplication.java
Created Mar 2, 2020
To know if App has gone to background or is in foreground
View MyApplication.java
public class MyApplication implements LifecycleObserver {
@Override
public void onCreate() {
ProcessLifecycleOwner.get().getLifecycle().addObserver(this);
}
@OnLifecycleEvent(Lifecycle.Event.ON_START)
public void onStart() {
Log.d("App in foreground");
@thsaravana
thsaravana / AppTransitionStatus.java
Last active Mar 2, 2020
Used to identify when the app goes to foreground or background
View AppTransitionStatus.java
public final class AppTransitionStatus implements Application.ActivityLifecycleCallbacks {
private static final long MAX_BACKGROUND_TIME = 2000;
private Timer timer;
private TimerTask task;
private boolean isBackground = true;
private final Transition transition;
public AppTransitionStatus(@NonNull Transition transition) {
You can’t perform that action at this time.