Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/202.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 通过intent.putExtra()发送信息_Android - Fatal编程技术网

Android 通过intent.putExtra()发送信息

Android 通过intent.putExtra()发送信息,android,Android,我发现几个线程“title like me”,但我的qus不同。我的qus正在使用intent。我可以只将数据发送到下一个调用活动吗?我可以在其他活动中不使用getExtra()方法吗?意思是我可以使用“key”在任何活动中获取数据吗 Intent i = new Intent(A.this, B.class); 例如 int number=5; Intent i = new Intent(A.this, B.class); i.putExtra("num

我发现几个线程“title like me”,但我的qus不同。我的qus正在使用intent。我可以只将数据发送到下一个调用活动吗?我可以在其他活动中不使用getExtra()方法吗?意思是我可以使用“key”在任何活动中获取数据吗

 Intent i = new Intent(A.this, B.class);
例如

     int number=5;   
     Intent i = new Intent(A.this, B.class);
     i.putExtra("numbers", number);
     startActivity(i);


     In the activity B i get the info:


     Bundle extras = getIntent().getExtras();
     int arrayB = extras.getInt("numbers");
 Intent i = new Intent(A.this, B.class);

我可以在任何其他活动中也获得它吗…?

您的意图将只引用一个活动(在本例中为B.activity.class),因此只有B能够提取额外的内容

 Intent i = new Intent(A.this, B.class);

如果第三个活动C需要该信息,您需要构建您的程序,以便B调用另一个意图(C.class),并向下传递相同的附加信息。

您的意图将只引用一个活动(在本例中为B.activity.class),因此只有B能够调出附加信息

 Intent i = new Intent(A.this, B.class);

如果第三个活动C需要该信息,您需要构建您的程序,以便B调用另一个意图(C.class),并向下传递相同的附加信息。

否。除非您无法将此意图发送到该活动,否则您无法在另一个活动中获得此信息

 Intent i = new Intent(A.this, B.class);
意图对象是一组信息。当您启动触觉时,我们会将信息传递给该活动。如果要将此捆绑包用于另一个活动,则必须传递给该活动

 Intent i = new Intent(A.this, B.class);
您可以按如下级别传递信息包

 Intent i = new Intent(A.this, B.class);
A->B->C

 Intent i = new Intent(A.this, B.class);

此处,活动A启动活动并将信息传递给B活动,与直接发送A->C

否时,您可以传递给C活动的捆绑包相同。除非您无法将此意图发送给该活动,否则您无法在其他活动中获得此信息

 Intent i = new Intent(A.this, B.class);
意图对象是一组信息。当您启动触觉时,我们会将信息传递给该活动。如果要将此捆绑包用于另一个活动,则必须传递给该活动

 Intent i = new Intent(A.this, B.class);
您可以按如下级别传递信息包

 Intent i = new Intent(A.this, B.class);
A->B->C

 Intent i = new Intent(A.this, B.class);
在这里,活动A启动活动并将信息传递给B活动以及您可以传递给C活动的相同捆绑包,正如您的代码所建议的那样,直接发送A->C

 int number=5;   
 Intent i = new Intent(A.this, B.class);
 i.putExtra("numbers", number);
 startActivity(i);
 Intent i = new Intent(A.this, B.class);
从队伍里

 Intent i = new Intent(A.this, B.class);
您的bundle对象仅在B活动中获取资源

 Intent i = new Intent(A.this, B.class);
编辑:您仅在已传递意图的活动中获取bundle对象。 因此,只有该活动才能接收它

 Intent i = new Intent(A.this, B.class);
如果您想访问其他活动中的数据,请使用共享首选项、sqlite、内部存储文件等

 Intent i = new Intent(A.this, B.class);
Thanx.

正如您的代码所示

 int number=5;   
 Intent i = new Intent(A.this, B.class);
 i.putExtra("numbers", number);
 startActivity(i);
 Intent i = new Intent(A.this, B.class);
从队伍里

 Intent i = new Intent(A.this, B.class);
您的bundle对象仅在B活动中获取资源

 Intent i = new Intent(A.this, B.class);
编辑:您仅在已传递意图的活动中获取bundle对象。 因此,只有该活动才能接收它

 Intent i = new Intent(A.this, B.class);
如果您想访问其他活动中的数据,请使用共享首选项、sqlite、内部存储文件等

 Intent i = new Intent(A.this, B.class);

Thanx.

您可以通过希望将数据发送到多个
活动的
活动
和希望接收
意图的
活动内注册来实现此目的。您可以阅读本教程,开始使用
广播接收器

您将能够通过希望向多个
活动发送数据的
活动
和希望接收
意图的
活动内注册来实现这一点。您可以阅读本教程,开始学习
广播接收机

hm。。。你也许应该告诉我们你想要实现什么。可能使用sendBroadcast()?确切地说,我不知道应该使用什么来实现相同的功能..但我想将一个活动变量/对象数据传输到与同一个包相关的任何其他类,因此如何实现此功能?我知道“静态”关键字也是一个选项,但我听说它不好,所以应该使用什么..再次感谢您的回复..嗯。。。你也许应该告诉我们你想要实现什么。可能使用sendBroadcast()?确切地说,我不知道应该使用什么来实现相同的功能..但是我想将一个活动变量/对象数据传输到与同一个包相关的任何其他类,那么如何实现呢?我知道“static”关键字也是一个选项,但我听说它不好,所以应该使用什么..再次感谢您的支持..嘿,pratik,如果我们是从a->c发送,那么我们必须在“B”上获取它,然后再次将它放在intent上?对吗?plsA->B->c和a->c是不同的。在A->C中,这里没有调用或使用B活动。嘿,pratik,如果我们从A->C发送,那么我们必须将其设置为“B”,然后再次将其设置为intent?对吗?plsA->B->C和A->C是不同的。在A->C中,此处未调用或使用任何B活动。
 Intent i = new Intent(A.this, B.class);