问题描述
我有9个活动在我的应用程序上点击我要开始活动randomly.Like按钮的(它可以比这不是一个固定值更提高)
I have 9 Activities (It can be increased more than this not a fixed value) in my App on Click of the Button i want to start activities randomly.Like
Activity 1 -> Activity ->3 and so on.
如果后退按钮用户点击我想再次完成当前的活动,并开始一个新的活动用户还没有被访问尚未..
And if the user clicks on the back button i want to finish the current activity and start again a new activity the the user haven't been visited yet ..
所以,我怎么能做到这一点。
So how could i do this .
对于随机的活动我都试过这种方式
For random activity i have tried this way
Random rnd = new Random();
int x=rnd.nextInt(9)+1;
Intent myIntent = new Intent();
switch(x){
case 1:
myIntent.setClass(view.getContext(),Scrn1.class);
break;
case 2:
myIntent.setClass(view.getContext(), Scrn2.class);
break;
case 3:
myIntent.setClass(view.getContext(), Scrn1.class);
break;
}
但我没有得到我怎么能启动,用户还没有访问过一个新的活动方式
But i am not getting the way how could i start a new activity that the user haven't visited yet
推荐答案
最简单的方法是使用共享preferences跟踪开始活动。例如,您可以储存类名或一些独特的活动的ID数组。在开始新的活动之前,先阅读阵列,看看发生了什么已经启动,选择新的活动课,更新preferences数组,并推出新的活动。
The easiest way is to use SharedPreferences to keep track of started activities. For example, you can store array with class names or some unique activity's id. Before starting new activity you read array, see what was started already, choose new activity class, update array in preferences and launch new activity.
这篇关于启动活动在随机的Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!