Why App Open Ads runs before MainActivity? - android

I'm asking why after I placed the App Open Ads in the AppOpenManager and some other code added on MyApplication same article that Google Admob advices to use but I'm still confused, Why when I launch my app:
The Splash screen : Open First
Then the App Open Ads opens and stay running in the background while the MainActivity opens above the App Open Ads.
If you know how to solve this help me please...
Thanks in advance.
Here is the GIF about the app I was using for the test to show you App Open Ads

Try this:
gradle:
implementation 'com.google.android.gms:play-services-ads:20.1.0'
def lifecycle_version = "2.2.0"
def lifecycle_version1 = "2.3.1"
implementation "androidx.lifecycle:lifecycle-extensions:$lifecycle_version"
implementation "androidx.lifecycle:lifecycle-runtime:$lifecycle_version1"
annotationProcessor "androidx.lifecycle:lifecycle-compiler:$lifecycle_version1"
Manifests
android:name=".MyApplication"
AppOpenManager.java
import android.app.Activity;
import android.app.Application;
import android.os.Bundle;
import android.util.Log;
import androidx.lifecycle.LifecycleObserver;
import androidx.lifecycle.OnLifecycleEvent;
import androidx.lifecycle.ProcessLifecycleOwner;
import com.google.android.gms.ads.AdError;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.FullScreenContentCallback;
import com.google.android.gms.ads.LoadAdError;
import com.google.android.gms.ads.appopen.AppOpenAd;
import java.util.Date;
import static androidx.lifecycle.Lifecycle.Event.ON_START;
public class AppOpenManager implements LifecycleObserver, Application.ActivityLifecycleCallbacks {
private long loadTime = 0;
private static final String LOG_TAG = "AppOpenManager";
private static String AD_UNIT_ID = "abc";
private AppOpenAd appOpenAd = null;
private Activity currentActivity;
private AppOpenAd.AppOpenAdLoadCallback loadCallback;
private static boolean isShowingAd = false;
private final MyApplication myApplication;
/** Constructor */
public AppOpenManager(MyApplication myApplication) {
this.myApplication = myApplication;
this.AD_UNIT_ID = myApplication.getString(R.string.app_open_id);
this.myApplication.registerActivityLifecycleCallbacks(this);
ProcessLifecycleOwner.get().getLifecycle().addObserver(this);
}
/** LifecycleObserver methods */
#OnLifecycleEvent(ON_START)
public void onStart() {
showAdIfAvailable();
Log.d(LOG_TAG, "onStart");
}
/** Request an ad */
public void fetchAd() {
// Have unused ad, no need to fetch another.
if (isAdAvailable()) {
return;
}
loadCallback =
new AppOpenAd.AppOpenAdLoadCallback() {
/**
* Called when an app open ad has loaded.
*
* #param ad the loaded app open ad.
*/
#Override
public void onAdLoaded(AppOpenAd ad) {
AppOpenManager.this.appOpenAd = ad;
AppOpenManager.this.loadTime = (new Date()).getTime();
}
/**
* Called when an app open ad has failed to load.
*
* #param loadAdError the error.
*/
#Override
public void onAdFailedToLoad(LoadAdError loadAdError) {
// Handle the error.
}
};
AdRequest request = getAdRequest();
AppOpenAd.load(
myApplication, AD_UNIT_ID, request,
AppOpenAd.APP_OPEN_AD_ORIENTATION_PORTRAIT, loadCallback);
}
/** Creates and returns ad request. */
private AdRequest getAdRequest() {
return new AdRequest.Builder().build();
}
/** Utility method to check if ad was loaded more than n hours ago. */
private boolean wasLoadTimeLessThanNHoursAgo(long numHours) {
long dateDifference = (new Date()).getTime() - this.loadTime;
long numMilliSecondsPerHour = 3600000;
return (dateDifference < (numMilliSecondsPerHour * numHours));
}
/** Utility method that checks if ad exists and can be shown. */
public boolean isAdAvailable() {
return appOpenAd != null && wasLoadTimeLessThanNHoursAgo(4);
}
/** ActivityLifecycleCallback methods */
#Override
public void onActivityCreated(Activity activity, Bundle savedInstanceState) {}
#Override
public void onActivityStarted(Activity activity) {
currentActivity = activity;
}
#Override
public void onActivityResumed(Activity activity) {
currentActivity = activity;
}
#Override
public void onActivityStopped(Activity activity) {}
#Override
public void onActivityPaused(Activity activity) {}
#Override
public void onActivitySaveInstanceState(Activity activity, Bundle bundle) {}
#Override
public void onActivityDestroyed(Activity activity) {
currentActivity = null;
}
/** Shows the ad if one isn't already showing. */
public void showAdIfAvailable() {
// Only show ad if there is not already an app open ad currently showing
// and an ad is available.
if (!isShowingAd && isAdAvailable()) {
Log.d(LOG_TAG, "Will show ad.");
FullScreenContentCallback fullScreenContentCallback =
new FullScreenContentCallback() {
#Override
public void onAdDismissedFullScreenContent() {
// Set the reference to null so isAdAvailable() returns false.
AppOpenManager.this.appOpenAd = null;
isShowingAd = false;
fetchAd();
}
#Override
public void onAdFailedToShowFullScreenContent(AdError adError) {}
#Override
public void onAdShowedFullScreenContent() {
isShowingAd = true;
}
};
appOpenAd.show(currentActivity);
} else {
Log.d(LOG_TAG, "Can not show ad.");
fetchAd();
}
}
}
MyApplication.java
import android.app.Application;
import com.google.android.gms.ads.MobileAds;
import com.google.android.gms.ads.initialization.InitializationStatus;
import com.google.android.gms.ads.initialization.OnInitializationCompleteListener;
/** The Application class that manages AppOpenManager. */
public class MyApplication extends Application {
private static AppOpenManager appOpenManager;
#Override
public void onCreate() {
super.onCreate();
MobileAds.initialize(
this,
new OnInitializationCompleteListener() {
#Override
public void onInitializationComplete(InitializationStatus initializationStatus) {}
});
appOpenManager = new AppOpenManager(this);
}
}

As Google have mentioned in "Cold starts and loading screens" Section here, app open ads will show when users foreground the app when it's suspended in memory. "Cold starts" occur when the app is launched but was not previously suspended in memory.
What we should do is avoid using System.exit(0) in onBackPressed() for exiting the app since it will make the app in Cold starts mode when opened. Just use finishAffinity() for exiting the app.

replace this
#OnLifecycleEvent(ON_START)
public void onStart() {
showAdIfAvailable();
}
with this
#OnLifecycleEvent(ON_START)
public void onStart() {
if (!(currentActivity instanceof SplashActivity)) {
showAdIfAvailable();
}
}

Related

How to use a CustomApplication class in a Flutter Plugin

I am generating a plugin in Flutter that will integrate a native library *.aar and this library needs to be initialized in the Application class of android, since it will extend the Application class of the library. The problem I am having is that at no time does it seem that the Application class is used in the Flutter plugin, I have tried to create the application class and define it in the plugin manifest, but at no time does it seem to enter the onCreate. I do not see how to solve this situation, any indication is welcome.
My class Application:
public class App extends SDKApplication{
#Override
public void onCreate() {
super.onCreate();
Log.e("App", "onCreate");
}
}
My manifest
<application
android:name=".App">
</application>
and the plugin class:
public class SdkPlugin implements FlutterPlugin, MethodCallHandler {
/// The MethodChannel that will the communication between Flutter and native Android
///
/// This local reference serves to register the plugin with the Flutter Engine and unregister it
/// when the Flutter Engine is detached from the Activity
private MethodChannel channel;
private EMTingSDK sdk = EMTingSDK.getInstance();
private Context context;
public SdkPlugin(){
Log.e("PRUEBAS","onMethodCall");
new App();
}
#Override
public void onAttachedToEngine(#NonNull FlutterPluginBinding flutterPluginBinding) {
context = flutterPluginBinding.getApplicationContext();
channel = new MethodChannel(flutterPluginBinding.getBinaryMessenger(), Constants.CHANNEL);
channel.setMethodCallHandler(this);
}
#Override
public void onMethodCall(#NonNull MethodCall call, #NonNull Result result) {
Log.e("PRUEBAS","onMethodCall");
if (call.method.equals("getPlatformVersion")) {
result.success("Android " + android.os.Build.VERSION.RELEASE);
}else {
result.notImplemented();
}
}
#Override
public void onDetachedFromEngine(#NonNull FlutterPluginBinding binding) {
channel.setMethodCallHandler(null);
}
}
P.D: I need to start it in the Application because the developers of the native library told us that it had to be spent in this way, then I will put a little more code regarding the application.
public class SDKApplication extends CompanyApplication implements ActivityLifecycleCallbacks {
public SDKApplication() {
}
public void onCreate() {
SDK.getInstance().setContext(this.getApplicationContext());
super.onCreate();
Log.i("InfoSDK", "SDKApplication - init from App ");
this.registerActivityLifecycleCallbacks(this);
}
public void onActivityCreated(Activity activity, Bundle bundle) {
SDK.getInstance().setHostActivity(activity);
}
public void onActivityStarted(Activity activity) {
}
public void onActivityResumed(Activity activity) {
SDK.getInstance().setHostActivity(activity);
}
public void onActivityPaused(Activity activity) {
}
public void onActivityStopped(Activity activity) {
}
public void onActivitySaveInstanceState(Activity activity, Bundle bundle) {
}
public void onActivityDestroyed(Activity activity) {
}
}
And the Company Application is:
public class CompanyApplication extends Application {
public CompanyApplication () {
}
public void onCreate() {
super.onCreate();
RequestQueue mainQueue = null;
if (SDK.getInstance().isDevelopEnviroment()) {
mainQueue = Volley.newRequestQueue(this.getApplicationContext(), new HurlStack((UrlRewriter)null, this.newSslSocketFactory()));
} else {
mainQueue = Volley.newRequestQueue(this.getApplicationContext());
}
CompanyHttpClient.getInstance().setMainQueue(mainQueue);
}
}

Error with the simple code using Loaders in android

I was trying to refactor my code and move my code from Async Task to a loader. I came to know about the benefits of loaders through the Android Performance video series Loaders Android Performance
I know why Loaders are used and what classes it has and stuff (The theory). However I am unable to grasp the working concept and thus wrote this poor code. Thus I am also not able to debug it.
**EDIT: I was able to make it work but I still think I am calling it in a wrong manner.
new EarthquakeAsyncTaskLoader(this).forceLoad();
If anyone can help me out, on this.........**
import android.content.AsyncTaskLoader;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.LoaderManager;
import android.support.v4.content.Loader;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import java.io.IOException;
import java.util.ArrayList;
public class EarthQuakeActivity extends AppCompatActivity implements LoaderManager.LoaderCallbacks<ArrayList<EarthQuakes>> {
ArrayList<EarthQuakes> earthquakes = null;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_earth_quake);
getSupportLoaderManager().initLoader(1, null, this);
}// End of onCreate
#Override
public Loader<ArrayList<EarthQuakes>> onCreateLoader(int id, Bundle args) {
**new EarthquakeAsyncTaskLoader(this).forceLoad();**
}
#Override
public void onLoadFinished(Loader<ArrayList<EarthQuakes>> loader, ArrayList<EarthQuakes> data) {
}
#Override
public void onLoaderReset(Loader<ArrayList<EarthQuakes>> loader) {
}
public class EarthquakeAsyncTaskLoader extends AsyncTaskLoader<ArrayList<EarthQuakes>> {
public EarthquakeAsyncTaskLoader(Context context) {
super(context);
}
#Override
protected void onStartLoading() {
// If the data is there, don't start again
if (earthquakes != null) {
deliverResult(earthquakes);
} else {
//Start the loader
forceLoad();
}
}
#Override
public ArrayList<EarthQuakes> loadInBackground() {
// Get the populated list from QueryUtils java class
try {
// Here in QueryUtils, I am making an HTTP network call
// Thus it has to be done in a helper background thread
earthquakes = QueryUtils.getArrayList();
} catch (IOException e) {
e.printStackTrace();
}
return earthquakes;
}
#Override
public void deliverResult(ArrayList<EarthQuakes> data) {
// Feed the adapter with data and display it
ListView earthquakesList = (ListView) findViewById(R.id.listV);
final EarthQuakeAdapter adapter = new EarthQuakeAdapter(getApplicationContext(), data);
earthquakesList.setAdapter(adapter);
earthquakesList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
EarthQuakes currentEarthquake = adapter.getItem(i);
Uri earthquakeUri = Uri.parse(currentEarthquake.getUrl());
// Create a new intent to view the earthquake URI
Intent websiteIntent = new Intent(Intent.ACTION_VIEW, earthquakeUri);
// Send the intent to launch a new activity
startActivity(websiteIntent);
}
});
}
}//End of Async Task Loader
//EarthQuakes is my class. I don't think you'll need this. But anyway:
public class EarthQuakes {
private double mMagnitude;
private String mLocationSmallText;
private String mLocationMainText;
private String mDateOfEarthquake;
private String mUrl;
// Default Constructor
public EarthQuakes(Double mag, String locationSmallText, String locationMainCityName, String dateE, String Url) {
this.mMagnitude = mag;
this.mLocationSmallText = locationSmallText;
this.mLocationMainText = locationMainCityName;
this.mDateOfEarthquake = dateE;
this.mUrl = Url;
}
// Public getters
public Double getMagnitude() {
return mMagnitude;
}
public String getLocationSmallTextEarthquake() {
return mLocationSmallText;
}
public String getLocationLargeTextEarthquake() {
return mLocationMainText;
}
public String getDateOfEarthquake() {
return mDateOfEarthquake;
}
public String getUrl() {
return mUrl;
}
}
This alternative will also work:
getSupportLoaderManager().initLoader(1, null, this).forceload();
However, this is just a way around an issue with loaders that is mentioned here.
This issue happens if you are using AsyncTaskLoader that is not a CursorLoader.
You need to implement onStartLoading() and handle calling forceLoad() there. Highly recommend going through the issue page.
If you are using multiple loaders throughout your app and don't want to implement onStartLoading() every time. Here's a custom loader class you can include in your app and inherit from this instead of the usual AsyncTaskLoader:
WrappedAsyncTaskLoader.java(Original Author: Alexander Blom)
public abstract class WrappedAsyncTaskLoader<D> extends AsyncTaskLoader<D> {
private D mData;
/**
* Constructor of <code>WrappedAsyncTaskLoader</code>
*
* #param context The {#link Context} to use.
*/
public WrappedAsyncTaskLoader(Context context) {
super(context);
}
/**
* {#inheritDoc}
*/
#Override
public void deliverResult(D data) {
if (!isReset()) {
this.mData = data;
super.deliverResult(data);
} else {
// An asynchronous query came in while the loader is stopped
}
}
/**
* {#inheritDoc}
*/
#Override
protected void onStartLoading() {
super.onStartLoading();
if (this.mData != null) {
deliverResult(this.mData);
} else if (takeContentChanged() || this.mData == null) {
forceLoad();
}
}
/**
* {#inheritDoc}
*/
#Override
protected void onStopLoading() {
super.onStopLoading();
// Attempt to cancel the current load task if possible
cancelLoad();
}
/**
* {#inheritDoc}
*/
#Override
protected void onReset() {
super.onReset();
// Ensure the loader is stopped
onStopLoading();
this.mData = null;
}
}

Android - Use the Activity callback in a standard java class

I'm developing an .aar library and I really need to interact with the lifecycle of an activity (so the callback onCreate(), on onResume(), etc...) in a standard java class.
I tried a lot of things but nothing works.
Is there a way I can do that?
From my understanding you need some thing like this,
import android.app.Activity;
import android.app.Application;
import android.os.Bundle;
/**
* #Krish
*/
public class LifeCycleObserver {
private LifeCycleObserver() {}
private static LifeCycleObserver sLifeCycleObserver;
public static LifeCycleObserver getInstance()
{
if (sLifeCycleObserver == null)
{
sLifeCycleObserver = new LifeCycleObserver();
}
return sLifeCycleObserver;
}
public static void init(Application application)
{
application.registerActivityLifecycleCallbacks(sLifeCycleObserver.lifecycleCallbacks);
}
private Application.ActivityLifecycleCallbacks lifecycleCallbacks = new Application.ActivityLifecycleCallbacks() {
#Override
public void onActivityCreated(Activity activity, Bundle savedInstanceState) {
}
#Override
public void onActivityStarted(Activity activity) {
}
#Override
public void onActivityResumed(Activity activity) {
}
#Override
public void onActivityPaused(Activity activity) {
}
#Override
public void onActivityStopped(Activity activity) {
}
#Override
public void onActivitySaveInstanceState(Activity activity, Bundle outState) {
}
#Override
public void onActivityDestroyed(Activity activity) {
}
};
}
and use it like this in Application class,
import android.app.Application;
/**
* Created by krish
*/
public class MyApplication extends Application {
#Override
public void onCreate() {
super.onCreate();
LifeCycleObserver.init(this);
}
}

How to ignore certain classes from LeakCanary?

Can someone give me a working example of how to ignoring certain classes from LeakCanary?
I was looking at this example for ignoring certain classes from third party library in LeakCanary, but I couldn't figure out where to put this in my application. I put this in my Application class, but there are error from these variables and methods: isInAnalyzerProcess, enableDisplayLeakActivity, application, androidWatcher
public class DebugExampleApplication extends ExampleApplication {
protected RefWatcher installLeakCanary() {
if (isInAnalyzerProcess(this)) {
return RefWatcher.DISABLED;
} else {
ExcludedRefs excludedRefs = AndroidExcludedRefs.createAppDefaults().build();
enableDisplayLeakActivity(application);
ServiceHeapDumpListener heapDumpListener = new ServiceHeapDumpListener(application, DisplayLeakService.class);
final RefWatcher refWatcher = androidWatcher(application, heapDumpListener, excludedRefs);
registerActivityLifecycleCallbacks(new ActivityLifecycleCallbacks() {
public void onActivityDestroyed(Activity activity) {
if (activity instanceof ThirdPartyActivity) {
return;
}
refWatcher.watch(activity);
}
// ...
});
return refWatcher;
}
}
}
Thanks to CommonsWare, calling the methods and variables on LeakCanary works. Here is a complete example for ignoring certain References or Activities in LeakCanary. Look at the comments: IGNORE Rreferences and IGNORE Activities.
import android.app.Activity;
import android.app.Application;
import android.content.Context;
import android.os.Bundle;
import com.squareup.leakcanary.AndroidExcludedRefs;
import com.squareup.leakcanary.DisplayLeakService;
import com.squareup.leakcanary.ExcludedRefs;
import com.squareup.leakcanary.LeakCanary;
import com.squareup.leakcanary.RefWatcher;
import com.squareup.leakcanary.ServiceHeapDumpListener;
public class MyApplication extends Application {
// LeakCanary for memory leak detection
private RefWatcher refWatcher;
public static RefWatcher getRefWatcher(Context context) {
MyApplication application = (MyApplication) context.getApplicationContext();
return application.refWatcher;
}
#Override
public void onCreate() {
super.onCreate();
refWatcher = installLeakCanary();
}
/**
* Excluding known memory leaks from third party libraries
* #return
*/
protected RefWatcher installLeakCanary() {
if (LeakCanary.isInAnalyzerProcess(this)) {
return RefWatcher.DISABLED;
} else {
// IGNORE References: Update or add reference class and context name in instanceField
ExcludedRefs excludedRefs = AndroidExcludedRefs.createAppDefaults()
.instanceField("com.example.third.party.TheirClassOne", "context")
.instanceField("com.example.third.party.TheirClassTwo", "context")
.build();
LeakCanary.enableDisplayLeakActivity(this);
ServiceHeapDumpListener heapDumpListener = new ServiceHeapDumpListener(this, DisplayLeakService.class);
final RefWatcher refWatcher = LeakCanary.androidWatcher(this, heapDumpListener, excludedRefs);
registerActivityLifecycleCallbacks(new ActivityLifecycleCallbacks() {
#Override
public void onActivityCreated(Activity activity, Bundle savedInstanceState) {
}
#Override
public void onActivityStarted(Activity activity) {
}
#Override
public void onActivitySaveInstanceState(Activity activity, Bundle outState) {
}
#Override
public void onActivityPaused(Activity activity) {
}
#Override
public void onActivityStopped(Activity activity) {
}
#Override
public void onActivityDestroyed(Activity activity) {
//IGNORE Activities: Update or add the class name here to ingore the memory leaks from those actvities
if (activity instanceof ThirdPartyOneActivity) return;
if (activity instanceof ThirdPartyTwoActivity) return;
if (activity instanceof ThirdPartyThreeActivity) return;
refWatcher.watch(activity);
}
#Override
public void onActivityResumed(Activity activity) {
}
});
return refWatcher;
}
}
}
In addtion to existing answer,
LeakCanary does watch(...) all Activity by default,
which you can disable like:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<bool name="leak_canary_watcher_auto_install">false</bool>
</resources>
See:
https://square.github.io/leakcanary/changelog/#configuring-retained-object-detection

Is there a way to force start an activity when the app comes to foreground?

I'm trying to integrate a pin entry activity that appears and is required for entry whenever the user opens the app. Including after the app is sent to the background and then brought to the foreground.
This question highlights ways to detect when the app is sent to the background: How to detect when an Android app goes to the background and come back to the foreground
I could use a method from here and check if the app went to the background. Then in the onResume() method I can start the pin entry activity if the app was not in the foreground.
Given this is a pin entry activity used to increase security, would force starting an activity in this way be reliable (Are there any other ways I have overlooked a user could open the app)?
Use Foreground.java class to check app is foreground or background
package com.mindsetapp;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import android.app.Activity;
import android.app.Application;
import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
public class Foreground implements Application.ActivityLifecycleCallbacks {
public static final long CHECK_DELAY = 500;
public static final String TAG = Foreground.class.getName();
public interface Listener {
public void onBecameForeground();
public void onBecameBackground();
}
private static Foreground instance;
private boolean foreground = false, paused = true;
private Handler handler = new Handler();
private List<Listener> listeners = new CopyOnWriteArrayList<Listener>();
private Runnable check;
/**
* Its not strictly necessary to use this method - _usually_ invoking
* get with a Context gives us a path to retrieve the Application and
* initialise, but sometimes (e.g. in test harness) the ApplicationContext
* is != the Application, and the docs make no guarantees.
*
* #param application
* #return an initialised Foreground instance
*/
public static Foreground init(Application application){
if (instance == null) {
instance = new Foreground();
application.registerActivityLifecycleCallbacks(instance);
}
return instance;
}
public static Foreground get(Application application){
if (instance == null) {
init(application);
}
return instance;
}
public static Foreground get(Context ctx){
if (instance == null) {
Context appCtx = ctx.getApplicationContext();
if (appCtx instanceof Application) {
init((Application)appCtx);
}
throw new IllegalStateException(
"Foreground is not initialised and " +
"cannot obtain the Application object");
}
return instance;
}
public static Foreground get(){
if (instance == null) {
throw new IllegalStateException(
"Foreground is not initialised - invoke " +
"at least once with parameterised init/get");
}
return instance;
}
public boolean isForeground(){
return foreground;
}
public boolean isBackground(){
return !foreground;
}
public void addListener(Listener listener){
listeners.add(listener);
}
public void removeListener(Listener listener){
listeners.remove(listener);
}
#Override
public void onActivityResumed(Activity activity) {
paused = false;
boolean wasBackground = !foreground;
foreground = true;
if (check != null)
handler.removeCallbacks(check);
try {
if (wasBackground){
Log.i(TAG, "went foreground");
if (!MindSetApp.flag_mute) {
MindSetApp.sound_flag=true;
if( MindSetApp.sound_flag)
{
if(!MindSetApp.mPlayer.isPlaying())
{
MindSetApp.mPlayer.start();
}
}
}
for (Listener l : listeners) {
try {
l.onBecameForeground();
} catch (Exception exc) {
Log.e(TAG, "Listener threw exception!", exc);
}
}
} else {
Log.i(TAG, "still foreground");
}
} catch (Exception e) {
e.printStackTrace();
}
}
#Override
public void onActivityPaused(Activity activity) {
paused = true;
if (check != null)
handler.removeCallbacks(check);
handler.postDelayed(check = new Runnable(){
#Override
public void run() {
if (foreground && paused) {
foreground = false;
for (Listener l : listeners) {
try {
l.onBecameBackground();
} catch (Exception exc) {
Log.e(TAG, "Listener threw exception!", exc);
}
}
} else {
Log.i(TAG, "still foreground"+MindSetApp.sound_flag);
}
}
}, CHECK_DELAY);
}
#Override
public void onActivityCreated(Activity activity, Bundle savedInstanceState) {}
#Override
public void onActivityStarted(Activity activity) {}
#Override
public void onActivityStopped(Activity activity) {}
#Override
public void onActivitySaveInstanceState(Activity activity, Bundle outState) {}
#Override
public void onActivityDestroyed(Activity activity) {}
}

Categories

Resources