Skip to content Skip to sidebar Skip to footer

How To Call Another Activity After Certain Time

At this moment I try to create an Android TV application. For example, I have 3 activities. I would like to call another activity after 10 seconds. How can I create this using And

Solution 1:

I have found a solution for this. You have to use Threading.

newThread(newThreadStart(() =>
                                 {
        Thread.Sleep(10000);
        RunOnUiThread(() =>
                      {
          Intent i = newIntent();
          i.SetClass(this, typeof(Activity2));
          StartActivity(i);

          this.Finish();
        });


      })).Start();   

Solution 2:

You can use AlaramManager to set the timing of the activity when to call.

Intent intentA=newIntent(context, A.class);

pendingIntent=PendingIntent.getBroadcast(this, 0, intentA, 0);

alarmManager=(AlarmManager)getSystemService(ALARM_SERVICE);

alarmManager.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,0,3000, pendingIntent);


Intent intentB=newIntent(context, B.class);

pendingIntent=PendingIntent.getBroadcast(this, 0, intentB, 0);

alarmManager=(AlarmManager)getSystemService(ALARM_SERVICE);

alarmManager.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,1000,3000, pendingIntent);


Intent intentC=newIntent(context, C.class);

pendingIntent=PendingIntent.getBroadcast(this, 0, intentC, 0);

alarmManager=(AlarmManager)getSystemService(ALARM_SERVICE);

alarmManager.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,2000,3000, pendingIntent);

I haven't tried it but it i think it would with little modification.

Solution 3:

Use no of Handlers to achieve this.Here this activity starts after 2 seconds

     Handler handler = new Handler();
               Runnable r=new Runnable() {
                         @Override
                         publicvoidrun() {
                           startActivity(new intent(xxx.this,yyy.class);
                         }         
                       };
                   handler.postDelayed(r, 2000);

Post a Comment for "How To Call Another Activity After Certain Time"