要关闭当前活动并启动另一项活动,如果用户没有做present屏幕上的任何工作。可以说我对活动1,我没有做任何工作,持续30秒。我想另一个活动说活性2会自动启动并完成活动1
To close the current activity and start another activity if the user does not do any work on the present screen. Say I am at Activity1 and I am not doing any work for 30 seconds. I want that another activity say Activity2 starts automatically and Activity1 finishes.
您可以创建一个变量和存储系统时间在里面活动1启动时。
You can create a variable and store the system time in it when Activity1 starts.
漱口当前系统时间此链接:的Android获取当前时间和日期
Refer this link for current System time: Android get current time and date
然后您可以创建一个循环,并检查变量的值是否是从系统的当前时间小于30秒。如果是的话,你可以调用的方法。
Then you can create a loop and check whether the variable's value is less than 30 sec from the System's current time. If yes you can call a method.
在该方法就可以开始新的活动(活性2)。
In the method you can start the new activity (Activity2).
//To start new activity
Intent intent=new Intent(your_current_class.this,activity_you_want_to_call.class);
startActivity(intent);