首页 > 解决方案 > 来自多个活动的意图

问题描述

我在从多个活动中获取数据时遇到问题。这是我的问题。

  1. 我做了 3 个活动来相互获取数据。(让我说 3 个活动 A、B、C)A、B 执行不同的方法,但它们的结果是相同的类型,即 ArrayList。我的目的是从 A、B 获得 C 中的两个结果。

活动-A

Intent intent = new Intent(RouteInfoDebug1.this, LiveLocationInfo.class);
Bundle bundle = new Bundle();
bundle.putStringArrayList("stdid", (ArrayList<String>) list);
intent.putExtras(bundle);
Log.d("LLNC", "Passed Value:" + (ArrayList<String>) list +"\n");
startActivity(intent);

活动-B

Intent intent = new Intent(LowBusInfo.this, LiveLocationInfo.class);
Bundle bundle = new Bundle();
bundle.putStringArrayList("lowStdid", (ArrayList<String>) list);
intent.putExtras(bundle);
Log.d("LLLC", "Passed Value:" + (ArrayList<String>) list +"\n");
startActivity(intent);

活动-C

Bundle bundle = getIntent().getExtras();
ArrayList<String> list = bundle.getStringArrayList("stdid");
Log.d("LLNC", "Received Value: " + bundle.getStringArrayList("stdid")+"\n");

ArrayList<String> lowList = bundle.getStringArrayList("lowStdid");
Log.d("LLLC", "Received Value: " + bundle.getStringArrayList("lowStdid")+"\n");

我是这样编码的。当我检查来自不同活动 A、B 的每个值(来自 Log.d 的传递值)时,它是完美的。

来自 A 列表:[null, 305001086, 305001087]

From B list: [null, 305001233, 305001241, 305001010, 305001123, 305001239, 305001273, 305001340, 305001143, 305001352, 305200048, 305001269, 305001275, 305001345, 305001167, 305001237, 305001434, 305001235, 305001354, 305001136, 305001227, 305001094, 305001243 , 305001380, 305000887, 305001159, 305001347, 305001247, 305001353, 305001346, 305001171, 305001231, 305001169, 305001086, 305001127, 305200003, 305001341, 305001274, 305001245, 305001155, 305001088, 305001342, 305001271, 305200054, 305001229, 305300257, 305001137, 305001165 , 305001153, 305001163]

但问题出在 Activity-C 中。我一直从一项活动中获得空值。例如,当我得到完整的 A 列表值时,我从 B 列表中得到 null,或者发生相反的情况。我用谷歌搜索了一整天,最后我发现有人说两个活动不能同时开始,所以我匹配了相同的密钥。但结果却是惨不忍睹。

这是详细目的:我想从C中的A,B获取每个数据,然后我想在A List和B List之间建立条件,对其进行优化并使用代码获取其他数据。

  1. 其实我是为了方便而分了活动。如果我将两个活动(A,B)组合成一个(但不同的类),可能是解决方案吗?这是我的第一个问题,抱歉太久了。提前致谢。

这将运行活动 A,然后播放活动 B。

public void mOnClick(View view){
          switch(view.getId()){
            case R.id.btnSearch:

                    new Thread(new Runnable(){
                        @Override
                        public void run(){
                            data = getRouteInfo();

                            /*Activity B's Method will be executed here*/
                            LowBusInfo lowBusInfo = (LowBusInfo)getApplication();
                            lowBusInfo.getLowBusInfo();

                            lowBusInfo.thread.start();

                            thread.start();

                            runOnUiThread(new Runnable(){
                                @Override
                                public void run(){
                                    textView.setText(data);
                                   }
                            });
                        }
                    }).start();
                    break;
            }
        }

标签: javaandroidandroid-intent

解决方案


推荐阅读