机器人可以从一个链接startActivityForResult收到一条活动的结果 [英] Android Can you get an activity result from a chained startActivityForResult
问题描述
我有以下活动的屏幕
活动A - 包含一个按钮链接到b活动
Activity A - contains a button that links to Activity B
b活动 - 包含为了确认,然后打开了一个活动℃的Next按钮(捕捉签名)
Activity B - contains a confirmation of order and then a Next button that opens up a Activity C (to capture signature)
活性Ç - 弹出供用户输入自己的签名和完整的按钮的对话框
Activity C - a dialog box that pops up for the user to enter their signature and a complete button.
活动A - 包含意图开始启动活动B和实现onActivityForResult
Activity A - contains intent start to start Activity B and implements onActivityForResult
Intent intent = new Intent( this, ConfirmLines.class );
startActivityForResult( intent, GET_SIGNATURE );
protected void onActivityResult( int requestCode, int resultCode, Intent intent )
{
super.onActivityResult( requestCode, resultCode, intent );
switch ( requestCode )
{
case GET_SIGNATURE:
if ( resultCode == RESULT_OK )
{
getIntent().putExtra( SIGNATURE_DATA, intent.getStringExtra( SignatureCapture.SIGNATURE_RESULT ) );
getIntent().putExtra( SIGNATURE_TIME, "34552655544" ); // todo - remove hardcoded signature time
showDialog( PRINT_NAME );
}
else
{
//reset data after a cancel/back from signature screen
getIntent().putExtra( SignatureCapture.SIGNATURE_RESULT, "" );
}
break;
}
}
b活动 - 包含code启动意图签名捕获,也onActivityForResult可以追溯到活动A
Activity B - contains code to start intent for signature capture and also onActivityForResult which goes back to Activity A.
final Intent intent = new Intent( this, SignatureCapture.class );
startActivityForResult( intent, GET_SIGNATURE );
@Override
protected void onActivityResult( int requestCode, int resultCode, Intent intent )
{
super.onActivityResult( requestCode, resultCode, intent );
switch ( requestCode )
{
case GET_SIGNATURE:
if ( resultCode == RESULT_OK )
{
finish();
}
}
}
活动Ç - 包含code代表签名捕获和完备的按钮
Activity C - contains the code for signature capture and a complete button
public void onClick( View view )
{
switch ( view.getId() )
{
case R.id.button_cancel:
dismiss();
nameValue.setText( "" );
notesValue.setText( "" );
imageView_button.setImageBitmap( null );
break;
case R.id.button_confirm:
final String printedText = String.valueOf( nameValue.getText() );
if ( printedText.isEmpty() )
{
Toast.makeText( getContext(), "Please enter a name", Toast.LENGTH_SHORT ).show();
}
else
{
if ( mDialogResult != null )
{
mDialogResult.finish( String.valueOf( nameValue.getText() ), String.valueOf( notesValue.getText() ) );
}
nameValue.setText( "" );
notesValue.setText( "" );
dismiss();
}
break;
}
}
我的陷入当我返回到活动A,结果code等于0,它被定义为结果被取消。
I am getting stuck when I get returned back to Activity A, the resultCode equals 0, which is defined as the result being cancelled.
为开始最初从活动A,但它只是这个结果code,这似乎是问题,如果任何人都可以看到它拿起正确的请求code,为什么?
It is picking up the correct requestCode as started originally from Activity A but it's just this resultCode that seems to be the problem, if anyone can see why?
难道有可能是做呼叫从b活动结束(),当它从活动ç回来?
Could it possibly be to do with calling finish() from Activity B when it is returned from Activity C?
此外,我需要从活动ç意图数据传递给A.如果我有b活动结束()如果我startActivity的活动一个接着它不会落入onActivityForResult。
Also, I am needing to pass Intent data from Activity C to A. Where I have finish() in Activity B if I startActivity for Activity A it then does not drop into onActivityForResult.
感谢您的帮助先进:]
Thanks for help in advanced :]
推荐答案
如果你想获得结果从活动下通过传递到:
If you would like to get the result from Activity C passed by to A:
开始b活动从活动答:
Intent showB = new Intent(ActivityA, ActivityB);
startActivityForResult(showB, RequestCode);
在b活动调用C:
Intent showC = new Intent(ActivityC);
showC.setFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT);
startActivity(showC);
finish(); //Close Activity B
在C:
//set the result code and close the activity
Intent result = new Intent();
setResult(resultCode, result);//like RESULT_OK
finish();
在答:
public void onActivityResult(int requestCode, int resultCode, Intent data) {
...... handle RequestCode here
}
这篇关于机器人可以从一个链接startActivityForResult收到一条活动的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!