ok I have two classes my main class calls a menu class when the user
gets done with that they press the back button to go to the main
class. on the main class I have onActivityResult setup but no matter
what the data field is null all the time even though I setup the
bundle and attached it to an Intent. Please look over my code and see
what it going on.
Main class
import android.app.Activity;
import android.os.Bundle;
import android.content.Intent;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
public class caralarm extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
@Override
public boolean onCreateOptionsMenu(Menu menu) {
new MenuInflater(this).inflate(R.menu.menu, menu);
return(super.onCreateOptionsMenu(menu));
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId()==R.id.close) {
Toast.makeText(this, "Trying to close app",
Toast.LENGTH_SHORT).show();
}
if (item.getItemId()==R.id.refresh) {
Toast.makeText(this, "Trying to refresh app",
Toast.LENGTH_SHORT).show();
}
if (item.getItemId()==R.id.settings) {
Toast.makeText(this, "Trying to open settings app",
Toast.LENGTH_SHORT).show();
launch_settings2();
}
return(super.onOptionsItemSelected(item));
}
protected void onActivityResult(int requestCode, int resultCode,
Intent data){
if (data == null)
{
Log.d ("data", "data was null");
Number = Settings2.Number; //this works
Password = Settings2.Passwordtext;
Often = Settings2.NumMin;
return;
}
Bundle extras = data.getExtras();
String name = extras.getString("Alarm");
Toast.makeText(this, name, Toast.LENGTH_SHORT);
}
void launch_settings2(){
Intent i = new Intent(this, Settings2.class);
startActivityForResult(i, 0);
}
}
Settings2 class
Import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.preference.PreferenceManager;
import android.widget.EditText;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
public class Settings2 extends PreferenceActivity{
static String Number = "";
static String Passwordtext = "";
static String NumMin = "";
protected void onCreate (Bundle savedInstanceState){
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.settings2);
}
public static String getNumber (Context context){
return
PreferenceManager.getDefaultSharedPreferences(context).getString("AlarmNumber",
Number);
}
public static String getPassword (Context context){
return
PreferenceManager.getDefaultSharedPreferences(context).getString("Password",
Passwordtext);
}
public static String getNumMin (Context context){
return
PreferenceManager.getDefaultSharedPreferences(context).getString("Often",
NumMin);
}
@Override
protected void onPause(){
super.onPause();
//copy data
Number = getNumber(this);
Passwordtext = getPassword(this);
NumMin = getNumMin(this);
Bundle info = new Bundle();
info.putString("Alarm", Number );
info.putString("Password", Passwordtext);
info.putString("Often", NumMin);
Intent intent = new Intent();
intent.putExtras(info);
setResult(RESULT_OK, intent);
finish();
}
}
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
To unsubscribe, reply using "remove me" as the subject.