问题:传递大量数据,以第二项活动数据、问题

2023-09-12 04:29:57 作者:素卿

我有一个奇怪的问题。我一直在寻找各地的网络,但没有找到答案。我仍然在机器人编程初学者。因此,让我们去:

我想要做的就是调用次活动的一些数据。能正常工作的小的数据,但如果数据变大时,第二活动将不会显示,第一个饰面。 这是我的$ C $调用方法C:

 意向意图=新的意图(ActivitySearch.this,ActivityResults.class);
束束=新包();
bundle.putParcelableArrayList(数据,searchList);
intent.putExtras(包);
startActivity(意向);
 

接收数据的部分是不重要的。即使我不尝试读取软件包,该活动将不会被调用。我测试过这与以下几行:

  @覆盖
公共无效的onCreate(包savedInstanceState){
Log.d(调试,ActivityResult:在OnCreate());
super.onCreate(savedInstanceState);
 

的OnCreate()被永远不会被调用。

也许和你们不相上下。有一个想法... 谢谢您的帮助!

编辑:至少我忘了:这仅ICS下发生。该应用程序的工作原理是用姜饼和Froyo的风情万种。

EDIT2:logcat的

  10-10 14:49:46.951:D / OpenGLRenderer(21696):刷新缓存(模式0)
10-10 14:49:47.011:V / ActivityThread(22429):上市慧深com.example.amazonsearch白
10-10 14:49:50.821:W / IInputConnectionWrapper(21696):showStatusIcon上的非活动InputConnection
 
截至目前全球数据中心并购交易价值额已突破2019年总和

解决方案

你可能得到TransactionTooLargeException

所建议的谷歌 Android的指南,你可以使用静态字段或单身共享数据之间的活动。

他们推荐共享复杂的非持久性的用户自定义对象的持续时间短

这是你的code,似乎也正是你所需要的。

所以,你的code在ActivitySearch.class可能看起来是这样的:

  ActivityResults.data = searchList;
意向意图=新的意图(ActivitySearch.this,ActivityResults.class);
startActivity(意向);
 

然后你可以从任何地方访问ActivityResults.data在ActivityResults活动启动后。

有关需要进行用户会话之间共享的数据,这是不建议使用静态字段,因为应用程序可以被杀死,而应用程序在后台运行(如果框架需要释放资源),通过Android框架重新启动。在这种情况下,所有的静态字段将被重新初始化。

I've got an strange issue. I was looking around the web but didn't find an answer. I'm still a beginner in android programming. So let's go:

All I want to do is calling the second Activity with some data. It works fine with small data, but if the data gets large, the second Activity will not show and the first one finishes. Here's my code of the calling Method:

Intent intent = new Intent(ActivitySearch.this,ActivityResults.class);
Bundle bundle = new Bundle();
bundle.putParcelableArrayList("data", searchList);
intent.putExtras(bundle);
startActivity(intent);

The part of receiving data is not important. Even if I don't try to read the bundle, the activity will not be called. I've tested this with following lines:

@Override
public void onCreate(Bundle savedInstanceState) {
Log.d("DEBUG","ActivityResult::onCreate()");
super.onCreate(savedInstanceState);

OnCreate() gets never called.

Maybe one of yours got an idea... Thank you for your help!

Edit:at least I forgot: This only happens under ICS. The app works like a charme with gingerbread and froyo.

Edit2: Logcat

10-10 14:49:46.951: D/OpenGLRenderer(21696): Flushing caches (mode 0)
10-10 14:49:47.011: V/ActivityThread(22429): com.example.amazonsearch white listed for hwui
10-10 14:49:50.821: W/IInputConnectionWrapper(21696): showStatusIcon on inactive InputConnection

解决方案

You are probably getting TransactionTooLargeException

As suggested by google android guide, you could use static fields or singletons to share data between activities.

They recommend it "For sharing complex non-persistent user-defined objects for short duration"

From your code it seems that's exactly what you need.

So your code in ActivitySearch.class could look something like this:

ActivityResults.data = searchList;
Intent intent = new Intent(ActivitySearch.this,ActivityResults.class);
startActivity(intent);

Then you can access ActivityResults.data from anywhere in ActivityResults activity after it starts.

For data that need to be shared between user sessions, it's not advisable to use static fields, since application process could be killed and restarted by android framework while app is running in background (if framework need to free resources). In such case all static fields will be reinitialized.