 |
|
|  |
¾Èµå·ÎÀÌµå ±¸±Û ¾Öµå¸÷ Àü¸é±¤°í ³Ö±â |
|
|
 |
8³â Àü |
package com.example;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
import com.google.android.gms.ads.InterstitialAd;
import android.app.Activity;
import android.widget.Toast;
public class BackPressCloseHandler {
private long backKeyPressedTime = 0;
private Toast toast;
private Activity activity;
private InterstitialAd interstitial;
public BackPressCloseHandler(Activity context)
{
this.activity = context;
Start ();
}
void Start () {
// ads
interstitial = new InterstitialAd(this.activity);
interstitial.setAdUnitId("ca-app-pub-**********************");
// Create an empty ad request.
AdRequest request = new AdRequest.Builder().build();
// Load the Ads with the request.
interstitial.loadAd(request);
}
public void onBackPressed()
{
if(System.currentTimeMillis() > backKeyPressedTime + 2000)
{
backKeyPressedTime = System.currentTimeMillis();
showToast();
return;
}
if(System.currentTimeMillis() <= backKeyPressedTime + 2000)
{
// activity.finish();
Utils.ShutdownApplication();
toast.cancel();
if(interstitial != null)
{
interstitial.show();
}
}
}
private void showToast()
{
toast = Toast.makeText(activity, "\'µÚ·Î\' ¹öÆ°À» Çѹø ´õ ´©¸£½Ã¸é Á¾·áµË´Ï´Ù.", Toast.LENGTH_SHORT);
toast.show();
}
}
À§ÀÇ ÄÚµå·Î Java Class¸¦ ¸¸µé°í °¢ ȸé Activity¿¡¼ ÇØ´ç Class¸¦ ÀÌ¿ëÇÏ¸é µÈ´Ù.
¾Æ·¡ ÄÚµå´Â °¢ Activity¿¡¼ »ç¿ëÇÏ´Â ºÎºÐÀÌ´Ù. ÇÙ½ÉÀûÀÎ ºÎºÐ¸¸ ÄÚµå·Î ³²°ÜµÐ´Ù.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);
backPressClosehandler = new BackPressCloseHandler(this);
}
|
|
̵̧ : 410 |
̵̧
¸ñ·Ï
|
|
|  |
|