I have searched and searched and I just can’t get this code to work.I have a main.xml layout and a setting.xml.I have some values I would like the Settings.class to change in my main apps class.Three string to be exact.
I have tried this simple test code in my main app class
settings.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
Intent intent = new Intent(v.getContext(), Settings.class);
startActivityForResult(intent, 0);
}
});
//Then a function
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent){
super.onActivityResult(requestCode, resultCode, intent);
Bundle extras = intent.getExtras();
String value = extras.getString("myKey");
if(value!=null){
Log.d("hmmm",value);
}
}
}
In my settings.class I have the following
returnHome.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
Intent intent = new Intent();
intent.putExtra("myKey", "YEAH");
setResult(RESULT_OK, intent);
finish();
}
});
Back in main app class it is not getting logged.
Like I said I have three string in the main class that I want settings class to change and send back.
Any help is greatly appreciated
I have had success with the technique used in the Notepad tutorial where the information is placed in a
Bundleand then added to the intent. See Step 10: