简体   繁体   中英

getting a result from startActivityForResult

i've a code that will get a image from the gallery and then set a gridSize with it.

the main code that will send android to the SizeSelection class.

PuzzleAcitivity:

if( resultCode == RESULT_OK) {
         Intent gridSizeIntent = new Intent();              
         gridSizeIntent.setClass(this, SizeSelection.class);
         startActivityForResult(gridSizeIntent, GRIDSIZE_VALUE_SELECT);
         createGameBoard(SizeSelection.getGridSize(this)); 
         }

but this is where the trouble kicks in: SizeSelection, when I hit the buttons that should activate and set a gridSize nothing happends. I think the problem is in getting the data from the SizeSelection to the main PuzzleActivity class.

sizeSelection:

protected static short getGridSize(Context content) {
        if ( mIbtn3x3 == view) {
             short gridSize = 3;
            return gridSize;
        }else if (mIbtn4x4 == view ) {
            short gridSize = 4;
            return gridSize;
        }else if (mIbtn5x5 == view ) {
            short gridSize = 5;
            return gridSize ;
        } 
            return gridSize;
        }

how am I supposed to finish the getGridSize method? thanks in advance

When you start an activity for result, your current code does not block. That is, startActivityForResult() returns quickly and you do not have the result yet. In order to receive the result (once it is available), you must provide an onActivityResult(int, int, Intent) method in your calling class. That method will be called automatically once the result is available.

In your child activity, you must do two things to provide the result. First, you call setResult(int) to provide the current expectation of what the result will be. This does not return anything, it just prepares the result -- you may change it if you wish at any time prior to the second step. Second, you call finish() to finish your activity.

See http://developer.android.com/reference/android/app/Activity.html for full documentation.

我认为当您比较mIbtn ... ==视图时,可能没有任何匹配项:)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM