Hello all. I'm new in Android and I'm building an app having some problems
in flow between Activity's
I have two activities, A and B.
My activity A have a button wich starts a Service, and have a button to
Activity B
My Activity B have a Save button wich saves some data to a file, and
returns to A
I'm also creating a Notification in A when the Service Starts.
When I leave A to the System, when I return from the Notification Bar or
from the Menu Icon, the system creates a new Instance of A and I wich to
access the same instance.
When I return from B to A, the same thing happen. But if I press the Back
Button, it shows the Instance of A already created
I already tried to to override
protected void onSaveInstanceState(Bundle outState) {
Log.i(STAMP, "Saving");
outState.putString("key", "value");
super.onSaveInstanceState(outState);
}
But in OnCreate, savedInstanceState is null.
I can't figure how to
do what I want.
The code:
Activity A
void start(){
//starts the service and create a notification icon
Log.i(STAMP, "starting");
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.notification_icon)
.setContentTitle("My notification")
.setContentText("Hello World!");
Intent resultIntent = new Intent(getApplicationContext(), A.class);
resultIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP |
Intent.FLAG_ACTIVITY_SINGLE_TOP);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
stackBuilder.addParentStack(MainActivity.class);
stackBuilder.addNextIntent(resultIntent);
PendingIntent resultPendingIntent =
stackBuilder.getPendingIntent(
0,
PendingIntent.FLAG_UPDATE_CURRENT
);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0,
resultIntent, 0);
mBuilder.setContentIntent(pendingIntent);
NotificationManager mNotificationManager =
(NotificationManager)
getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(1, mBuilder.build());
notificationIntent = new Intent(this, ComunicateService.class);
startService(notificationIntent);
txtStatus.setText(RUNNING_MSG);
}
Activity B
void save(){
//save to file and returns to A
//todo UPLOAD TO WEB
if (is_valid()) {
util.io_sharedPreferences_clear(DB_NAME, mContext);
util.io_sharedPreferences_write(DB_NAME, NO_MOV,
etNoMov.getText().toString(), mContext);
util.io_sharedPreferences_write(DB_NAME, NO_SIGN,
etNoSign.getText().toString(), mContext);
util.io_sharedPreferences_write(DB_NAME, SYNC_PERIOD,
Integer.toString(spinnerSync.getSelectedItemPosition()), mContext);
Intent i = new Intent(this, A.class);
startActivity(i);
finish();
}
else
util.showShortMessage(getResources().getString(R.string.str_errors),
this);
}
Thanks in advance
--
You received this message because you are subscribed to the Google Groups
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/android-developers.
To view this discussion on the web visit
https://groups.google.com/d/msgid/android-developers/e1bdc65f-858c-4fa1-8c1e-daaae98f1c53%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.