the program doesnt call onActivityResult, ive been in many post as this but i cant make it work.
Im using Android 3.0 Emulator.
this is the code of GameScreen.java
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch(requestCode) {
case 0: {
if (resultCode == Activity.RESULT_OK) {
String newText = data.getStringExtra("isRunning");
// TODO Update your TextView.
isRunning = true;
}
break;
}
}
}
public void pause(){
clickListener = new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
pause.setImageResource(R.drawable.pauseafter);
isRunning = false;
Intent intent = new Intent(Gamescreen.this, Shop.class);
startActivityForResult(intent, 0);
}
};
}
this is the code Shop.java
public void returnButton(){
resume.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent();
setResult(Activity.RESULT_OK,intent);
finish();
}
});
}
To test I’ve created simple application. Nothing fancy, just default layout and two activities. Toast in
onActivityResultis shown properly.Here’s complete working code:
file
OnReturnActivity.java:file
GimmeReturn.java:Both activities need to be added to Android manifest. Activity
OnReturnActivityhas action MAIN and category LAUNCHER (and is started as main activity for application). ActivityGimmeResultis just added without any IntentFilter.