从活动1-转移时2 - > 3 - > 2。回到活动1而不是活动2

时间:2013-11-11 04:44:33

标签: android android-intent android-activity pass-data

假设我有三个活动A,B,C。 程序的流程应该是A-> B-> C-> B。 我有意刺激采摘颜色的活动(C)。 我遇到的问题是

正在调用活动C.

startActivityForResult(i, 1);         我已经覆盖了Lib函数

        @Override
            protected void onActivityResult(int requestCode, int resultCode, Intent it)
            {
                super.onActivityResult(requestCode, resultCode, it);
                //String t;
                int r,g,b,a;
                r=g=b=a=0;
                System.out.println("onActivityResult " + it);
                System.out.println("onActivityResult " + resultCode);
                System.out.println("onActivityResult " + requestCode);//Intent it = getIntent();
                if(resultCode == RESULT_OK && requestCode==1)
                {
                    System.out.println("ColorPickerActivity 3");
                    r = it.getIntExtra("RED",0);
                    //it.getIntExtra("RED", r);
                    System.out.println("ColorPickerActivity R" + r);
                    g = it.getIntExtra("GREEN", 0);
                    System.out.println("ColorPickerActivity G" + g);
                    b = it.getIntExtra("BLUE", 0);
                    System.out.println("ColorPickerActivity B" + b);
                    a = it.getIntExtra("ALPHA", 0);
                    System.out.println("ColorPickerActivity A" + a);
                }
                System.out.println("ColorPickerActivity A" + graphIndex);
                this.r = (float) (r/255); this.g = (float)g/255; this.b = (float)b/255; this.a = (float)a/255;
                ChangeColor(this.r, this.g, this.b, this.a);
            }`

但是我的活动C甚至在单击Button之前就完成了,因为我已经为该Button实现了OnClickListener

        showColor.setOnClickListener(new OnClickListener()
        {
            @Override
            public void onClick(View v)
            {
                System.out.println("Color R G B A " + r + g+ +b + a);
                if(colorPickerObject != null)
                {
                   System.out.println("Color R G B A " + r + g +b + a);
                       r = colorPickerObject.getRed();
                       g = colorPickerObject.getGreen();
                       b = colorPickerObject.getBlue();
                       a = colorPickerObject.getAlpha();
                       System.out.println("Color R G B A " + r + g +b + a);
                       setIntent();
                }
            }
        });

函数setIntent()如下

    public void setIntent()
        {
            Intent i = new Intent();
            i.putExtra("RED", r);
            i.putExtra("GREEN", g);
            i.putExtra("BLUE", b);
            i.putExtra("ALPHA", a);
            setResult(RESULT_OK,i);
            System.out.println("Intent" + i );
            System.out.println("Intent R" + r );
            System.out.println("Intent G" + g );
            System.out.println("Intent B" + b );
            finish();
        }

请帮我解释为什么此活动C不会返回活动B.     相反,它过早地将Data作为空// onActivityResult结束,并将resultCode作为-1返回 原木

11-11 10:57:00.535: I/System.out(2476): ColorPickerActivity
11-11 10:57:00.535: I/System.out(2476): ColorPickerActivity 1Intent { cmp=com.example.sample3dchart/com.example.colorpicker.ColorPickerActivity }
11-11 10:57:00.535: I/ActivityManager(391): START u0 {cmp=com.example.sample3dchart/com.example.colorpicker.ColorPickerActivity} from pid 2476
11-11 10:57:00.550: I/System.out(2476): ColorPickerActivity 2
11-11 10:57:00.565: I/System.out(2476): COLORPICKER Activity
11-11 10:57:00.635: D/mali_winsys(2476): new_window_surface returns 0x3000
11-11 10:57:00.800: I/ActivityManager(391): Displayed com.example.sample3dchart/com.example.colorpicker.ColorPickerActivity: +247ms
11-11 10:57:05.205: I/System.out(2476): Color R G B A 0000
11-11 10:57:05.205: I/System.out(2476): Color R G B A 0000
11-11 10:57:05.205: I/System.out(2476): Color R G B A 3625536255
11-11 10:57:05.205: I/System.out(2476): IntentIntent { (has extras) }
11-11 10:57:05.205: I/System.out(2476): Intent R36
11-11 10:57:05.205: I/System.out(2476): Intent G255
11-11 10:57:05.205: I/System.out(2476): Intent B36
11-11 10:57:05.275: D/dalvikvm(391): GC_FOR_ALLOC freed 885K, 25% free 17310K/22824K, paused 58ms, total 58ms
11-11 10:57:05.285: I/System.out(2455): MAIN  START CALLED
11-11 10:57:05.300: D/mali_winsys(2455): new_window_surface returns 0x3000
11-11 10:57:05.305: W/InputMethodManagerService(391): Starting input on non-focused client com.android.internal.view.IInputMethodClient$Stub$Proxy@42a86a68 (uid=10066 pid=2476)
11-11 10:57:05.370: W/BufferQueue(2476): [unnamed-2476-0] cancelBuffer: BufferQueue has been abandoned!
11-11 10:57:05.650: I/ActivityManager(391): No longer want com.android.packageinstaller (pid 2118): empty #17
11-11 10:57:08.930: D/dalvikvm(1213): GC_CONCURRENT freed 405K, 5% free 9052K/9484K, paused 2ms+2ms, total 24ms
11-11 10:57:08.945: D/Finsky(1213): [1] 5.onFinished: Installation state replication succeeded.

也检查这些日志。不会崩溃但返回活动A

2 个答案:

答案 0 :(得分:0)

setIntent()似乎也是一些内置函数的名称。尝试更改功能的名称。

答案 1 :(得分:0)

清单文件有android:noHistory="true" 删除它,我的代码工作正常。