在我的应用程序中,我需要快速 询问用户input.
我需要从这个 Flash-Activity 获得一个结果,然后回到上一个.
我已经读过这个StartActivityForResult()方法,但我还不确定如何正确使用它,任何例子?
编辑:
我试图通过intent(作为结果)使用我在应用于StartActivityForResult()的此方法的所有应用程序中使用的方法传递Player对象:
在我的第二个Activity(我需要得到结果的那个):
Intent intent = new Intent();
Player playerKilled = players.get(position);
Bundle bundle = new Bundle();
bundle.putSerializable("PLAYER_KILLED", (Serializable) playerKilled);
intent.putExtras(bundle);
setResult(Activity.RESULT_OK, intent);
finish();
Run Code Online (Sandbox Code Playgroud)
我的主要活动,我需要将结果带到:
if (resultCode == Activity.RESULT_OK) {
Intent intent = this.getIntent();
Bundle bundle = intent.getExtras();
playerKilled = (Player)bundle.getSerializable("PLAYER_KILLED");
Toast.makeText(this, playerKilled.getName() + "the " + playerKilled.getCardName() + " has died, and he/she had the ID: " + playerKilled.getId(), Toast.LENGTH_SHORT).show();
Run Code Online (Sandbox Code Playgroud)