Android - 2 Activities active at the same time

…衆ロ難τιáo~ 提交于 2019-12-24 00:32:17

问题


I have a GameActivity. I also have a transparent ChatActivity running on top if the user presses the Chat options from the Menu (onOptionsItemSelected). The problem is, when a player starts the ChatActivity before I start the game, an odd behavior occurs and the game won't start.

Is there any way I can keep GameActivity active while ChatActivity is visible? I fired up the ChatActivity using the normal way:

startActivity(new Intent(GameActivity.this, ChatActivity.class));

Thanks for your help.


回答1:


You can't have two activities in one activity. However; one design you could possibly achieve is introduce a design that allows the user to swipe the screen to bring up the chat view and swipe in the opposite direction to hide the view.

Have the main Activity that is running maintain that view via an async process so that it can be updated as necessary and does NOT interrupt the user.




回答2:


You could take a look at FLAG_NOT_TOUCH_MODAL (and maybe FLAG_NOT_TOUCHABLE), using 2 activities on top of each other, making the top one transparant and give it that flag/those flags (not sure if you can actually touch windows you create within that activity, didn't try that yet)

you could also take a look at this. It's not exactly the same thing, but maybe you could rework it a bit to fit your needs




回答3:


I know this is very very late,but this answer could be of use of anyone new.

For achieving the kind of design mentioned here, you could implement fragments instead of having two activities.



来源:https://stackoverflow.com/questions/9093119/android-2-activities-active-at-the-same-time

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!