-2

我遇到了一些简单的问题。

我试图ArrayList<String>通过这样的意图:

        lupa.setOnClickListener(new OnClickListener(){

        @Override
        public void onClick(View v) {
            Intent intent = new Intent(MainActivity.this, lupa.class);
                    System.out.println(lista2); // Shows me the ArrayList<String>
            intent.putStringArrayListExtra("lista",lista2);
                    System.out.println("done"); // Checking
            startActivity(intent);  
                    System.out.println("done2"); // Checking again
        }

'lista2' 是一个全局变量: ArrayList<String> lista2 = new ArrayList<String>();,但我也尝试使用局部变量,并且我尝试使用 Bundle 进行操作。

发生的情况是:应用程序突然关闭,没有任何消息,LogCat 上也没有消息。我只是把三个System.out.println(...)正确,但正如我所说,它会在没有任何消息的情况下关闭。

问题是 100% 的,intent.putStringArrayListExtra("lista",lista2);因为如果我评论它,//它会把我带到另一个活动。

怎么了?


我发现我创建了一个ArrayList<String>这样的简单程序:

                ArrayList<String> lista3 = new ArrayList<String>();
            lista3.add("ola");
            lista3.add("k");
            lista3.add("ase");

它适用于intent.putStringArrayListExtra("lista",lista3);

ArrayList<String>是全球性的,我试图通过以下方式复制它:

ArrayList<String> lista3 = new ArrayList<String>();
lista3 = (ArrayList<String>)lista2.clone(); // lista2 is the global one

或者

ArrayList<String> lista3 = new ArrayList<String>(lista2);

什么也没发生intent.putStringArrayListExtra("lista",lista3);


我又得到消息了。

所以我觉得lista2.size()5528很大。

我正在做 FOR 并将东西添加到列表中,我终于得到了我可以在活动之间传递3374的最大大小。ArrayList<String>如果我设置3375相同的情况(它关闭时没有消息)......


现在我可以得到(我现在不知道为什么)Logcat:

11-01 00:19:27.025: D/PowerManagerService(2017): acquireDVFSLockLocked : type : DVFS_MIN_LIMIT  frequency : 1000000  uid : 1000  pid : 2017  tag : ActivityManager
11-01 00:19:27.025: W/ActivityManager(2017): mDVFSLock.acquire()
11-01 00:19:27.045: V/AlarmManager(2017): waitForAlarm result :1
11-01 00:19:27.085: V/AlarmManager(2017): trigger ELAPSED_REALTIME_WAKEUP or RTC_WAKEUP
11-01 00:19:27.085: W/AlarmManager(2017): FACTORY_ON= 0
11-01 00:19:27.095: V/AlarmManager(2017): waitForAlarm result :1
11-01 00:19:27.095: V/AlarmManager(2017): trigger ELAPSED_REALTIME_WAKEUP or RTC_WAKEUP
11-01 00:19:27.135: E/JavaBinder(2017): !!! FAILED BINDER TRANSACTION !!!
11-01 00:19:27.185: W/ActivityManager(2017): Exception when starting activity com.example.ricettenapoli/.lupa
11-01 00:19:27.185: W/ActivityManager(2017): android.os.TransactionTooLargeException
11-01 00:19:27.185: W/ActivityManager(2017):    at android.os.BinderProxy.transact(Native Method)
11-01 00:19:27.185: W/ActivityManager(2017):    at android.app.ApplicationThreadProxy.scheduleLaunchActivity(ApplicationThreadNative.java:731)
11-01 00:19:27.185: W/ActivityManager(2017):    at com.android.server.am.ActivityStack.realStartActivityLocked(ActivityStack.java:713)
11-01 00:19:27.185: W/ActivityManager(2017):    at com.android.server.am.ActivityStack.startSpecificActivityLocked(ActivityStack.java:841)
11-01 00:19:27.185: W/ActivityManager(2017):    at com.android.server.am.ActivityStack.resumeTopActivityLocked(ActivityStack.java:1799)
11-01 00:19:27.185: W/ActivityManager(2017):    at com.android.server.am.ActivityStack.resumeTopActivityLocked(ActivityStack.java:1426)
11-01 00:19:27.185: W/ActivityManager(2017):    at com.android.server.am.ActivityStack.completePauseLocked(ActivityStack.java:1174)
11-01 00:19:27.185: W/ActivityManager(2017):    at com.android.server.am.ActivityStack.activityPaused(ActivityStack.java:1072)
11-01 00:19:27.185: W/ActivityManager(2017):    at com.android.server.am.ActivityManagerService.activityPaused(ActivityManagerService.java:4467)
11-01 00:19:27.185: W/ActivityManager(2017):    at android.app.ActivityManagerNative.onTransact(ActivityManagerNative.java:396)
11-01 00:19:27.185: W/ActivityManager(2017):    at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:1695)
11-01 00:19:27.185: W/ActivityManager(2017):    at android.os.Binder.execTransact(Binder.java:367)
11-01 00:19:27.185: W/ActivityManager(2017):    at dalvik.system.NativeStart.run(Native Method)
11-01 00:19:27.195: D/WindowManager(2017): PhoneWindowManager: focusChangedLw

任何想法?


编辑:我ArrayList<String>的太大了,所以我将它存储在一个文件中并加载到另一个活动中。

谢谢!

4

1 回答 1

0

尝试:

intent.putStringArrayListExtra("lista",lista);

在 lupa.class Activity,您可以通过以下方式获取此列表:

ArrayList<String> lista = (ArrayList<String>) getIntent().getStringArrayListExtra("lista");
于 2013-10-31T10:39:02.067 回答