简体   繁体   English

如何使用计时器弹出活动

[英]How to make an activity popup with timer

Hello guys how are you today I hope you are OK I have an application with many activity's : 大家好,我今天你好,我希望你没事我有一个有很多活动的应用程序:

  • Main-activity 主要活动
  • activity1 活动1
  • activity2 活性2
  • activity3 activity3

what I need to do is make the activity3 popup every (x) minute, for example, every 2 or 3 minutes the activity3 popup how can I do that and thanks in advance. 我需要做的是每隔(x)分钟进行一次activity3弹出,例如,每2或3分钟,activity3弹出一次,我该如何做,并提前感谢。

public class MainActivity extends Activity { 公共类MainActivity扩展Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    //Remove notification bar
    this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
    //Remove title bar
    this.requestWindowFeature(Window.FEATURE_NO_TITLE);

    //load the xml file for the starting loading screen
    setContentView(R.layout.activity_main);

    Log.d("MainActivity:", "onCreate: created activity_main.xml UI succesfully.");

    new Timer().schedule(new TimerTask(){
        public void run() {
            startActivity(new Intent(MainActivity.this, PrimaryActivity.class));
            finish();

            Log.d("MainActivity:", "onCreate: waiting 5 seconds for MainActivity... loading PrimaryActivity.class");
        }
    }, 5000 );
}

} }

I didn't know how to try this before posting so I need your help thanks in advance. 在发布之前我不知道如何尝试这个,所以我需要你的帮助,提前谢谢。

'Make the popup function static and call it with class name like' '使弹出功能静止,并使用类名调用它'

yourclassname.popupFunction(Context); yourclassname.popupFunction(上下文);

'in on create method where you want to open the primary activity' '在创建方法中,您要打开主要活动'

public static void popupFunction(Activity activity){
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
              startActivity(new Intent(activity, PrimaryActivity.class));
              finish();

              Log.d("MainActivity:", "onCreate: waiting 5 seconds for MainActivity... 
                     loading PrimaryActivity.class");


            }
        },5000);
    }

'Hope you get the answer Thanks' '希望你得到答案谢谢'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM