Java 在android中通过意图传递捆绑包时获取主活动上的捆绑包
所以我遇到的问题是,我的应用程序在发布时不断崩溃,我有两个活动。活动A和活动B。我的应用程序在活动A上启动,但我已在活动B中创建了一个捆绑包,并将其发送到活动A。因此,当它启动捆绑包时,捆绑包为空或为空,因此会崩溃,我如何修复此问题?谢谢 这在创建时的活动A(启动活动)中Java 在android中通过意图传递捆绑包时获取主活动上的捆绑包,java,android,android-intent,android-activity,android-bundle,Java,Android,Android Intent,Android Activity,Android Bundle,所以我遇到的问题是,我的应用程序在发布时不断崩溃,我有两个活动。活动A和活动B。我的应用程序在活动A上启动,但我已在活动B中创建了一个捆绑包,并将其发送到活动A。因此,当它启动捆绑包时,捆绑包为空或为空,因此会崩溃,我如何修复此问题?谢谢 这在创建时的活动A(启动活动)中 Bundle extras = getIntent().getExtras(); Title = extras.getString("Title"); Description = extras.getS
Bundle extras = getIntent().getExtras();
Title = extras.getString("Title");
Description = extras.getString("Description");
Price = extras.getString("Price");
Availability = extras.getString("Availability");
然后我们让我在活动B中创建包
Intent intent = new Intent(B.this, A.class);
Bundle extras = new Bundle();
extras.putString("Title", PostTitle);
extras.putString("Description", PostDescription);
extras.putString("Price", PostPrice);
extras.putString("Availability", PostAvail);
intent.putExtras(extras);
startActivity(intent);
我建议如下: A.出于目的使用捆绑包:
Intent pIntent = new Intent(this, JustaClass.class);
Bundle extras = pIntent.getExtras();
extras.putString(key, value);
B.创建一个新的捆绑包:
Intent pIntent = new Intent(this, JustaClass.class);
Bundle pBundle = new Bundle();
pBundle.putString(key, value);
mIntent.putExtras(pBundle);
C.使用putExtra()方法:
Intent pIntent = new Intent(this, JustaClass.class);
pIntent.putExtra(key, value);
最后,在启动的活动中,您可以通过以下内容阅读:
String value = getIntent().getExtras().getString(key)
我只是使用字符串作为传递的示例,我参考了and。请发布您的代码可能的副本