开始的活动有一个参数 [英] Start an Activity with a parameter

查看:120
本文介绍了开始的活动有一个参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很新的Andr​​oid开发。

I'm very new on Android development.

我要创建并启动一项活动,以显示有关游戏的信息。我表明的信息,我需要一个gameId。

I want to create and start an activity to show information about a game. I show that information I need a gameId.

我怎样才能通过这个游戏ID的活动?游戏ID是绝对必要的,所以我不希望创建或启动活动,条件是不具备的ID。

How can I pass this game ID to the activity? The game ID is absolutely necessary so I don't want to create or start the activity if it doesn't have the ID.

这就像该活动得到了唯一的一个构造一个参数。

It's like the activity has got only one constructor with one parameter.

我怎么能这样做?

感谢。

推荐答案

把一个 INT 这是你的身份证到新的意图

Put an int which is your id into the new Intent.

Intent intent = new Intent(FirstActivity.this, SecondActivity.class);
Bundle b = new Bundle();
b.putInt("key", 1); //Your id
intent.putExtras(b); //Put your id to your next Intent
startActivity(intent);
finish();

然后抓住ID在新的活动

Bundle b = getIntent().getExtras();
int value = b.getInt("key");

这篇关于开始的活动有一个参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆