[android-developers] Problem when coming back to activity after changing font in Galaxy S
Hi All,
I am going through a strange behaviour. I have Two activities in my
application - ActivityOne and ActivityTwo. Both are very simple
activities and have only basic lifecycle methods overrridden.
Steps to reproduce this are as follows:
1. I am launching ActivityTwo by clicking on a button on ActivityOne.
For this I am using startActivityForResult() method.
2. Now when I am on ActivityTwo, I long press home key and go to
Settings > Display > Font Style. and change fonts.
3. Now I go back to ActivityTwo by pressing back button.
4. On ActivityTwo I press again back key.
Ideally while pressing back on ActivityTwo, It should call
AcitivityOne's onActivityResult() method.
But Here I saw, that first iActivityOne's onDestroy(), then onCreate()
and then onActivityResult() is called.
Because onCreate() is getting called it again launches ActivityTwo and
hence it feels to user that ActivityTwo is coming twice while pressing
back and user has to press back button twice for going to
ActivityOne.
This is a very strange behavoiur.
On digging more i found out that when font are getting changed, they
are restarting all packages. Hence all the activities are getting
created(instantiated) again. Because of this the first instance of
ActivityOne is getting killed and a new instance is getting created.
Because of this onCreate method is called and it again launches
ActivityTwo.
Here my problem is that, I can not make my activities singleinstance
or singletask. This is a requirement.
I also found that the same situation occurs in many of the pre-
installed applications or any of the newly created method.
My questions are:
1. Is there any config attribute for font changes? I tried to find out
in android docs and in google also but no luck yet.
2. If there is no config attribute, then please tell me the ways to
handle this situation. Its very weired situation for the user
ActivityOne Code is
public class ActivityOne extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button button = (Button) findViewById(R.id.btn_launch);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Log.d("ActivityOne", "<SURESH> setOnClickListener()");
Intent intent = new Intent();
intent.setComponent(new ComponentName("com.demo.backpress",
"com.demo.backpress.ActivityTwo"));
startActivityForResult(intent, 1);
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode,
Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(resultCode == RESULT_CANCELED) {
Toast.makeText(this, "First activity cancelled",
Toast.LENGTH_LONG);
}
Log.d("ActivityOne", "<SURESH> onActivityResult() resultCode ==> " +
resultCode + " -:- requestCode ==> " + requestCode + " -:- data ==> "
+ data);
}
}
ActivityTwo Code is :
public class ActivityTwo extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.d("ActivityTwo", "<SURESH> onCreate()");
setContentView(R.layout.main_two);
}
@Override
protected void onActivityResult(int requestCode, int resultCode,
Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Log.d("ActivityTwo", "<SURESH> onActivityResult() resultCode ==> " +
resultCode + " -:- requestCode ==> " + requestCode + " -:- data ==> "
+ data);
}
}
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home