0

假设,我有三个活动 A、B、C。程序的流程应该是A->B->C->B。我有意图激发采摘颜色的活动(C)。我遇到的问题是 Activity 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 甚至在它的按钮被点击之前就完成了,因为我已经实现了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。而是它过早地结束给Datanull //onActivityResult并返回resultCode为 -1 LOGS

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

4

2 回答 2

0

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

于 2013-11-12T05:47:31.697 回答
0

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

于 2013-11-11T04:52:47.437 回答