简体   繁体   English

Android在活动之间切换

[英]Android switching between activities

I currently have an activity called RaceActivity in my app which performs a setContentView() to display a surface view. 我目前在我的应用程序中有一个名为RaceActivity的活动,该活动执行setContentView()来显示表面视图。 Inside of my surface view I am checking to see if the user has won my game and when he/she has I would like to switch to another view that shows a simple game finished message. 在我的表面视图中,我正在检查用户是否赢得了我的游戏,以及他/她何时拥有,我想切换到另一个显示简单游戏结束消息的视图。 I have tried using: 我试过使用:

Intent intent = new Intent();         
intent.setClass(getContext(), RaceActivity.class); 
intent.putExtra("code", 3);
((Activity)getContext()).startActivityForResult(intent, 5);

But this doesn't work for me. 但这对我不起作用。 It shows the new view for a second then the screen goes black and it continues to execute the code on the previous surface view (I have a log statement so that I can see what it's doing). 它显示新视图一秒钟,然后屏幕变黑,并且继续在前一个表面视图上执行代码(我有一条log语句,以便可以看到它在做什么)。

How do I switch to the finish view and make it stop the previous view? 如何切换到完成视图并使其停止上一个视图?

To start another activity and STAY in that activty, you want to use startActivity (Intent intent) 要启动另一个活动并在该活动中停留,您需要使用startActivity(意图意图)

Try this instead 试试这个

Intent intent = new Intent();         
intent.setClass(getContext(), RaceActivity.class); 
intent.putExtra("code", 3);
((Activity)getContext()).startActivity(intent);

try like this 这样尝试

            Intent intent=new Intent(this,newclassname.class);
            intent.putExtra("code", 3);
            startActivityForResult(intent,0);

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

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