当使用TimerTask()显示添加时,应用程序返回主屏幕

时间:2014-09-19 04:56:41

标签: android timertask

这是我创建的第一个应用程序,我是android新手,

我正在设计一个显示广告屏幕的应用,用户打开应用时每隔1分钟

广告屏幕按预期完美运行,但问题是当广告屏幕退出时,无论用户当前在活动屏幕的哪个位置,应用都会返回到主屏幕

应用流程

SplashScreen.java - > AdSplash - > DiamondWorldMenus(主屏幕)

DiamondWorldMenus .java

public class DiamondWorldMenus extends TabActivity implements OnClickListener {


on Create(.......){

    public void startAdSplashForEvery1Minutes(){
            //starting AdSplashTimer.java every 5 minutes
            Timer myTimer = new Timer();

            myTimer.schedule(new TimerTask() {      

                @Override
                public void run() {
                    runOnUiThread(new Runnable() {

                        @Override
                        public void run() {
                            // TODO Auto-generated method stub
                            Intent viewTargetActivity = new Intent(getBaseContext(), AdSplash.class);
                            startActivity(viewTargetActivity);
                        }
                    });
                }
            },60000, 60000);
        }
  }

}

AdSplash.java

public class AdSplash extends Activity 
{
    protected boolean _active = true;
    protected int _splashTime = 8000;
    WebView ad;
    WebSettings web_settings;
    WebViewClient yourWebClient;

    @Override
    public void onCreate(Bundle savedInstanceState) 
    {


        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
        super.onCreate(savedInstanceState);
        setContentView(R.layout.ad_splash);
        String url = "http://some_add_link.aspx";
        yourWebClient = new WebViewClient();
        ad=(WebView)findViewById(R.id.ad_web);
        ad.getSettings().setJavaScriptEnabled(true);  
        ad.getSettings().setSupportZoom(true);       
        ad.getSettings().setBuiltInZoomControls(true); 
        ad.setWebViewClient(yourWebClient);
        ad.loadUrl(url);







              Thread splashTread = new Thread() 
        {
            @Override
            public void run() 
            {
                try 
                {
                    int waited = 0;
                    while(_active && (waited < _splashTime)) 
                    {
                        sleep(100);
                        if(_active) 
                            waited += 100;
                    }
                }
                catch(InterruptedException e) 
                {}
                finally 
                {
                    finish();
                    Intent in1 = new Intent(AdSplash.this,DiamondWorldMenus.class);
                    startActivity(in1);
                }
            }
        };
        splashTread.start();
    }
}

0 个答案:

没有答案