last day (15 days later) » 

9:58 PM
0
A: onSaveInstanceState() not saving data from the intent

Eugene HNot sure if you got it to work or not. But I got it to work with this. public class TestingForSO extends ActionBarActivity { private static final String ENAME = "ENAME"; EditText etename; String name = ""; @Override protected void onCreate(Bundle savedInstanceState) { ...

 
I have the same code right?
 
I would run it in a seperate activity to test it out. It must be an error in your code if it is not working.
 
I believe the code snippet is working. What I'm asking you guys is to help me figure out what's wrong with my code
 
Try getting rid of the strings in the onSaveInstanceState. Just string the edittext into the value and test it. Let me know if that works.
 
nope, doesn't work
 
9:58 PM
Okay then, lets call Log.e("Called","onSaveInstanceState"); in saved instance state. Log.e("Called","Load"); in the onCreate != null. Let me know what is called.
Let me know if you are in the chat.
 
yes I am
 
Hey have a look at the latest post how i am checking to see what is called.
 
it's calling onSaveInstanceState
 
OKay what about if (savedInstanceState != null) {
name = savedInstanceState.getString(ENAME, "");
Log.e("NAME", "saved");
} else{
Log.e("NAME", "not_saved");
}
 
not_saved
 
10:06 PM
odd
 
hmm
 
Okay does saved get called at all
 
nope
 
Call the super before everything. And are you just doing a screen rotation?
 
screen rotation is locked
 
10:10 PM
Then how are you testing the saved instance state?
 
I am clicking on a button which takes me to another intent
it's all described in my question
and I moved the super to the top. Still nothing
 
Okay. What are you calling in the second activity to go back to the first activity?
 
final Intent yourIntent = new Intent(Map2.this, EventCreateN.class);
startActivity(yourIntent);
 
See you are recreating the activity. Meaning the savedinstancestate == null
Just call finish();
 
oh
so what can I do?
but I'm sending some data from that class as a bundle
 
10:14 PM
Okay. Then we need to think of another solution. Perhaps startActivityForResult.
 
actually it's not a bundle I'm sending. I'm using putExtra()
 
Okay. what are you trying to send back to the previous activity?
 
the location
an address
 
How many strrings?
 
yourIntent.putExtra("key",add0 + "," + add1);
two
 
10:17 PM
Okay it looks like it is only one extra correct?
 
yeah
 
Okay I will put something together quick give me a minute
 
okay thanks a lot
 
No problem.
 startActivityForResult(intent, 2);
Put this in the 1st activity.
replace startActivity
 
startActivityForResult(map,1);
I have that
you want me to make it 2?
 
10:19 PM
Yes
 
done
that's all?
 
String address;

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 2) {
address = data.getStringExtra("ADDRESS");
}
}
Then add that to the main Activity.
1st activity
 
btw I have an onActivityResult already
used in getting an image from the gallery
on the same activity
if I add this, it will conflict right?
 
Okay, you just need to use different request codes.
Intent intent = new Intent();
intent.putExtra("MESSAGE", add0 + "," + add1);
setResult(2, intent);
finish();
Put this in your second activity.
Intent intent = new Intent();
intent.putExtra("ADDRESS", add0 + "," + add1);
setResult(2, intent);
finish();
Sorry you need to use ADDRESS not MESSAGE
As long as there are different request codes it wont be an issue.
Log.e("ADDRESS", address); within the requestcode 2
 
it says duplicate method onActivityResult
 
10:26 PM
??
Send me the link to all of the code of the first activiyt
 
yeah I told you right, I already have an onActivityResult method
 
Yea just send me the link to your code
 
String address;
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
try {
// When an Image is picked
if (requestCode == RESULT_LOAD_IMG && resultCode == RESULT_OK
&& null != data) {
// Get the Image from data

Uri selectedImage = data.getData();
String[] filePathColumn = { MediaStore.Images.Media.DATA };

// Get the cursor
Cursor cursor = getContentResolver().query(selectedImage,
filePathColumn, null, null, null);
String address;

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
try {
// When an Image is picked
if (requestCode == RESULT_LOAD_IMG && resultCode == RESULT_OK
&& null != data) {
// Get the Image from data

Uri selectedImage = data.getData();
String[] filePathColumn = {MediaStore.Images.Media.DATA};

// Get the cursor
Cursor cursor = getContentResolver().query(selectedImage,
filePathColumn, null, null, null);
 
just add
if (requestCode == 2) {
address = data.getStringExtra("ADDRESS");
Log.e("ADDRESS", address);
}
}
is it?
 
10:34 PM
Yes.
 
I added it before the else clause
is that ok?
img=outputStream.toByteArray();
//String str = new String(img, "US-ASCII");
//Log.d("image byte array", str);
if (requestCode == 2) {
address = data.getStringExtra("ADDRESS");
Log.e("ADDRESS", address);
}
//}

} else {

Toast toast= Toast.makeText(getApplicationContext(),
"You haven't picked Image", Toast.LENGTH_SHORT);
toast.setGravity(Gravity.CENTER|Gravity.CENTER_HORIZONTAL, 0, 0);
toast.show();
}
} catch (Exception e) {
Toast toast= Toast.makeText(getApplicationContext(),
"Something went wrong", Toast.LENGTH_SHORT);
 
Hold on Just replace the entire onActivity result with what I am about to send you
String address;

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
try {
// When an Image is picked
if (requestCode == RESULT_LOAD_IMG && resultCode == RESULT_OK
&& null != data) {
// Get the Image from data

Uri selectedImage = data.getData();
String[] filePathColumn = {MediaStore.Images.Media.DATA};

// Get the cursor
Cursor cursor = getContentResolver().query(selectedImage,
filePathColumn, null, null, null);
Run it and let me know if it logs it
 
nope,it doesn't log it
empty
I tried setting the value of address to the text view too
 
Damn. What the hell
 
ikr!
 
10:46 PM
okat then change the reuwst code to 101 in both activities
 
what?
reuwst?
 
setResult(101, intent);
Make sure you have all of them at 101 for that intent
 
I set if (requestCode == 101) and setResult(101, intent);
still nothing
 
damn
I will have to get back to you
Have to eat dinner with the girl
 
oh okay sure
reply me when you get back
have a good time
 
10:55 PM
Shoot me you email
 
chirathh@yahoo.com
 

last day (15 days later) »