Android退出動畫下廣告不出錯詳解

——–不加任何權限 AD
@Override
 public void onBackPressed() {
  // TODO Auto-generated method stub
  super.onBackPressed();
  Intent i = new Intent(Intent.ACTION_MAIN);

  i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

  i.addCategory(Intent.CATEGORY_HOME);

  startActivity(i);
 }

 

————電視動畫
public boolean onOptionsItemSelected(MenuItem item) {

  // TODO Auto-generated method stub
  if (item.getItemId() == 1) {
   AlertDialog.Builder builder = new

Builder(caipiaoActivity.this);

   builder.setTitle("福彩3D,體彩排列軟件信

息");
   builder.setMessage(R.string.about);

   builder.create().show();

  } else {
   mLinearLayout.startAnimation(new

TVOffAnimation());
   new Timer().schedule(new TimerTask() {

    @Override
    public void run() {
     // TODO Auto-generated

method stub
    

android.os.Process.killProcess(android.os.Process.myPid());

    }
   }, 1000);
  }

  return true;
 }

————-返回
public boolean onKeyDown(int keyCode, KeyEvent event)
 {
 

// TODO Auto-generated method stub
  // return

super.onKeyDown(keyCode, event);
  if (keyCode ==

KeyEvent.KEYCODE_BACK)
  {
   new

AlertDialog.Builder(this)
    

.setIcon(android.R.drawable.ic_dialog_alert)
   

 .setTitle(R.string.loginout_title)
   

 .setMessage(R.string.loginout_msg)
   

 .setPositiveButton(
     

 R.string.confirm,
     

 new android.content.DialogInterface.OnClickListener()
 

     {

   

    @Override
   

    public void onClick

(DialogInterface dialog,
     

    int which)
   

    {
    

    // TODO Auto-generated method

stub
        

Intent startMain = new Intent(
     

     Intent.ACTION_MAIN);
 

      

startMain.addCategory(Intent.CATEGORY_HOME);
   

     startMain
  

       

.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
   

     startActivity(startMain);
 

       

System.exit(0);
       

}
      

}).setNegativeButton(R.string.cancel, null)
   

 .create().show();
   return false;
 

}
  return false;
 }

 

————-動畫總結
加推送廣告 安裝之後殺瞭進程不會彈出窗口,關閉動畫播放正常.
刪除返回值.
public void onBackPressed() {
  // TODO Auto-generated method stub

  AlertDialog.Builder builder = new

  Builder(caipiaoActivity.this);

  builder.setTitle("提示");
  builder.setMessage("是否要退出福彩3D體彩排列軟

件");
  builder.setPositiveButton("確定",
    new

android.content.DialogInterface.OnClickListener() {

     @Override
     public void onClick

(DialogInterface dialog, int which) {
      // TODO Auto-

generated method stub
     

mLinearLayout.startAnimation(new TVOffAnimation());
      new Timer

().schedule(new TimerTask() {

       @Override
       public

void run() {
       

// TODO Auto-generated method stub
       

android.os.Process
        

 .killProcess(android.os.Process.myPid());
       }
      }, 1000);

     }
    }).setNegativeButton("取消",

null);

  builder.create().show();

 }

————退出不加入動畫 AD推送安裝正常,直接安裝不出現彈出窗口

再自動關回.
public void onBackPressed() {
  // TODO Auto-generated method stub
  super.onBackPressed();
  Intent i = new Intent(Intent.ACTION_MAIN);

  i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

  i.addCategory(Intent.CATEGORY_HOME);

  startActivity(i);

 

 

摘自 gongzibai的專欄

發佈留言