Android - 2 Activities active at the same time

2019-07-19 06:50发布

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.

3条回答
我欲成王,谁敢阻挡
2楼-- · 2019-07-19 07:07

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

查看更多
Evening l夕情丶
3楼-- · 2019-07-19 07:16

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.

查看更多
萌系小妹纸
4楼-- · 2019-07-19 07:28

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.

查看更多
登录 后发表回答