android.arch.lifecycle.ProcessLifecycleOwner Java Examples
The following examples show how to use
android.arch.lifecycle.ProcessLifecycleOwner.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BaseApplication.java From android-mvp-realtime-chat with MIT License | 5 votes |
@Override public void onCreate() { super.onCreate(); // Observer to detect if the app is in background or foreground. AppLifeCycleObserver lifeCycleObserver = new AppLifeCycleObserver(getApplicationContext()); // Adding the above observer to process lifecycle ProcessLifecycleOwner.get() .getLifecycle() .addObserver(lifeCycleObserver); }
Example #2
Source File: HomeActivity.java From alpha-wallet-android with MIT License | 5 votes |
public HomeActivity() { importFileName = null; if (VisibilityFilter.hideDappBrowser()) dappBrowserFragment = new Fragment(); else dappBrowserFragment = new DappBrowserFragment(); transactionsFragment = new TransactionsFragment(); settingsFragment = new NewSettingsFragment(); walletFragment = new WalletFragment(); lifeCycle = new LifecycleObserver() { @OnLifecycleEvent(Lifecycle.Event.ON_START) private void onMoveToForeground() { Log.d("LIFE", "AlphaWallet into foreground"); ((WalletFragment)walletFragment).walletInFocus(); } @OnLifecycleEvent(Lifecycle.Event.ON_STOP) private void onMoveToBackground() { Log.d("LIFE", "AlphaWallet into background"); ((WalletFragment)walletFragment).walletOutOfFocus(); } @Override public int hashCode() { return super.hashCode(); } }; ProcessLifecycleOwner.get().getLifecycle().addObserver(lifeCycle); }
Example #3
Source File: TronWalletApplication.java From tron-wallet-android with Apache License 2.0 | 4 votes |
public void onCreate() { super.onCreate(); Stetho.initializeWithDefaults(this); mFirebaseAnalytics = FirebaseAnalytics.getInstance(this); mFirebaseAnalytics.logEvent(FirebaseAnalytics.Event.APP_OPEN, new Bundle()); mContext = getApplicationContext(); mDatabase = Room.databaseBuilder(mContext, TronWalletDatabase.class, DATABASE_FILE_NAME) .addMigrations(TronWalletDatabase.MIGRATION_1_2) .build(); mIsInForeground = false; ProcessLifecycleOwner.get().getLifecycle().addObserver(this); Map<BlockExplorerUpdater.UpdateTask, Long> updaterIntervals = new HashMap<>(); updaterIntervals.put(BlockExplorerUpdater.UpdateTask.Blockchain, BLOCKCHAIN_UPDATE_INTERVAL); updaterIntervals.put(BlockExplorerUpdater.UpdateTask.Nodes, NETWORK_UPDATE_INTERVAL); updaterIntervals.put(BlockExplorerUpdater.UpdateTask.Witnesses, NETWORK_UPDATE_INTERVAL); updaterIntervals.put(BlockExplorerUpdater.UpdateTask.Tokens, TOKENS_UPDATE_INTERVAL); updaterIntervals.put(BlockExplorerUpdater.UpdateTask.Accounts, ACCOUNTS_UPDATE_INTERVAL); BlockExplorerUpdater.init(this, updaterIntervals); AccountUpdater.init(this, ACCOUNT_UPDATE_FOREGROUND_INTERVAL); PriceUpdater.init(this, PRICE_UPDATE_INTERVAL); SharedPreferences sharedPreferences = getSharedPreferences(getString(R.string.preference_file_key), Context.MODE_PRIVATE); if(sharedPreferences.getBoolean("logged_previous_transactions", false)) { SharedPreferences.Editor editor = sharedPreferences.edit(); List<Transaction> dbTransactions = TronWalletApplication.getDatabase().transactionDao().getAllTransactions(); for(Transaction dbTransaction : dbTransactions) { Bundle bundle = new Bundle(); bundle.putString("sender_address", dbTransaction.senderAddress); bundle.putString("hash", Hex.toHexString(Hash.sha256(dbTransaction.transaction.getRawData().toByteArray()))); bundle.putString("contract", Utils.getContractName(dbTransaction.transaction.getRawData().getContract(0))); mFirebaseAnalytics.logEvent("sent_transaction", bundle); } editor.putBoolean("logged_previous_transactions", true); } }
Example #4
Source File: Tracker.java From snowplow-android-tracker with Apache License 2.0 | 4 votes |
/** * Creates a new Snowplow Tracker. * * @param builder The builder that constructs a tracker */ private Tracker(TrackerBuilder builder) { this.context = builder.context; this.emitter = builder.emitter; this.appId = builder.appId; this.base64Encoded = builder.base64Encoded; this.namespace = builder.namespace; this.subject = builder.subject; this.devicePlatform = builder.devicePlatform; this.sessionContext = builder.sessionContext; this.sessionCheckInterval = builder.sessionCheckInterval; this.sessionCallbacks = builder.sessionCallbacks; this.threadCount = builder.threadCount < 2 ? 2 : builder.threadCount; this.timeUnit = builder.timeUnit; this.geoLocationContext = builder.geoLocationContext; this.mobileContext = builder.mobileContext; this.applicationCrash = builder.applicationCrash; this.trackerDiagnostic = builder.trackerDiagnostic; this.lifecycleEvents = builder.lifecycleEvents; this.screenviewEvents = builder.screenviewEvents; this.activityTracking = builder.activityTracking; this.onlyTrackLabelledScreens = builder.onlyTrackLabelledScreens; this.screenState = new ScreenState(); this.screenContext = builder.screenContext; this.installTracking = builder.installTracking; this.applicationContext = builder.applicationContext; this.gdpr = builder.gdpr; this.level = builder.logLevel; if (trackerDiagnostic) { if (level == LogLevel.OFF) { level = LogLevel.ERROR; } Logger.setErrorLogger(this); Logger.updateLogLevel(level); } if (this.installTracking) { this.installTracker = new InstallTracker(this.context); } else { this.installTracker = null; } // When session context is enabled if (this.sessionContext) { Runnable[] callbacks = {null, null, null, null}; if (sessionCallbacks.length == 4) { callbacks = sessionCallbacks; } this.trackerSession = Session.getInstance( builder.foregroundTimeout, builder.backgroundTimeout, builder.timeUnit, builder.context, callbacks[0], callbacks[1], callbacks[2], callbacks[3] ); } // If lifecycleEvents is True if ((this.lifecycleEvents || this.sessionContext) && Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { // addObserver must execute on the mainThread Handler mainHandler = new Handler(context.getMainLooper()); mainHandler.post(new Runnable() { @Override public void run() { ProcessLifecycleOwner.get().getLifecycle().addObserver(new ProcessObserver()); } }); } Logger.v(TAG, "Tracker created successfully."); }