Frage

Suppose, I have three activities A,B,C. The flow of the program is supposed to be A->B->C->B. I have intents to stimulate an activity for picking color(C). The problem that I am encountering is that the Activity C is being called by

startActivityForResult(i, 1); And I have overridden the Lib function

        @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);
            }`

But my activity C completes even before its Button is Clicked as I have Implemented an OnClickListener to that Button.

        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();
                }
            }
        });

The function setIntent() is as follows

    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();
        }

Please help me out why is this Activity C not returning to the Activity B. Rather it end prematurely giving Data as null //onActivityResult and returns the resultCode as -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.

Check these Logs too. Doesnt Crash here but returns to Activity A

War es hilfreich?

Lösung 2

The Manifest File had android:noHistory="true" Removed it and my code works fine.

Andere Tipps

setIntent() seems to be the name of some inbuilt function as well. try changing the name of the function.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top