Problem when coming back to activity after changing font in Galaxy S

by Suresh Pal » Fri, 20 May 2011 13:05:31 GMT


Sponsored Links
 i 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 cl



Re: Problem when coming back to activity after changing font in Galaxy S

by Simon Jackson » Fri, 20 May 2011 13:15:40 GMT


 how about to singleton something

static Activity me;

oncreate() 
if(me==null)
me = this
<docreate>
else
me.<focus>
finish();

or such

Cheers Jacko

-- 


Sponsored Links


Re: Re: Problem when coming back to activity after changing font in Galaxy S

by Suresh Chandra Pal » Fri, 20 May 2011 15:45:34 GMT


 Hi Simon,
You suggested to make activity singleton.
But is 'making activity' singleton not equal to single instance.
At a time I'll be having a single instance. and I dont want to do that.
Moreover mainly, I want a way which is acceptable according to android
concepts.
and if that is not possible then only I will have to do some trick.
But in any case I dont want my activity to be singleinstance or singletask.

That's why I want something android specific.

If I got you wrong then please explain your solution.









-- 

Best Wishes,



Suresh Pal



*Skype:               *suresh.pal

*Gtalk:*                sapient.suresh

*Facebook:*
 http://www.facebook.com/people/Suresh-Chandra-Pal/676583036 

*LinkedIn: *          http://www.linkedin.com/in/sapientsuresh 

*Blogs:  *               http://www.sapientsuresh.blogspot.com 

*Twitter: *             http://twitter.com/sapientsuresh 

*Google Profile:  * http://www.google.com/profiles/sapient.suresh 

-- 



Re: Re: Problem when coming back to activity after changing font in Galaxy S

by Suresh Chandra Pal » Fri, 20 May 2011 17:13:36 GMT


 Sorry for the wrong code, but the ActivityOne do not have a button, but is
starting ActivityTwo immediately in its onCreate() method. and this code is
creating problem.


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
Log.d("ActivityOne", "<SURESH> setOnClickListener()");
 Intent intent = new Intent();
intent.setComponent(new ComponentName("com.demo.backpress",
"com.demo.backpress.ActivityTwo"));
 startActivityForResult(intent, 1);
    }



On Fri, May 20, 2011 at 1:14 PM, Suresh Chandra Pal <






-- 

Best Wishes,



Suresh Pal



*Skype:               *suresh.pal

*Gtalk:*                sapient.suresh

*Facebook:*
 http://www.facebook.com/people/Suresh-Chandra-Pal/676583036 

*LinkedIn: *          http://www.linkedin.com/in/sapientsuresh 

*Blogs:  *               http://www.sapientsuresh.blogspot.com 

*Twitter: *             http://twitter.com/sapientsuresh 

*Google Profile:  * http://www.google.com/profiles/sapient.suresh 

-- 



Other Threads

1. Programmatically Adding a LinearLayout Error

I am trying to add a LinearLayout using only code to a Activity and I
keep getting as error.  Here is a proof of concept piece of code:

ackage org.syperiorsoft;



import android.app.Activity;
import android.os.Bundle;
import android.view.Gravity;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;

public class ViewTest extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        LinearLayout llRoot = (LinearLayout)findViewById(R.id.someid);
        if ( llRoot != null )
        {
                LinearLayout llDetails = new LinearLayout(this);
                llDetails.setLayoutParams(new LayoutParams
(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
                llDetails.setGravity(Gravity.LEFT);

                ImageView imEdit = new ImageView(this);
                imEdit.setImageResource(R.drawable.edit);
                imEdit.setLayoutParams(new LayoutParams(32, 32));

                LinearLayout llVert = new LinearLayout(this);
                        llVert.setOrientation(LinearLayout.VERTICAL);
                        llVert.setLayoutParams(new 
LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));

                        llDetails.addView(imEdit);
                        llDetails.addView(llVert);


                        llRoot.addView(llDetails);
        }
    }
}



Here is the stack:

Thread [<3> main] (Suspended (exception RuntimeException))
        LinearLayout.getBaseline() line: 151
        LinearLayout.measureHorizontal(int, int) line: 644
        LinearLayout.onMeasure(int, int) line: 280
        LinearLayout(View).measure(int, int) line: 7115
        LinearLayout(ViewGroup).measureChildWithMargins(View, int, int, int,
int) line: 2875
        LinearLayout.measureChildBeforeLayout(View, int, int, int, int, int)
line: 888
        LinearLayout.measureVertical(int, int) line: 350
        LinearLayout.onMeasure(int, int) line: 278
        LinearLayout(View).measure(int, int) line: 7115
        FrameLayout(ViewGroup).measureChildWithMargins(View, int, int, int,
int) line: 2875
        FrameLayout.onMeasure(int, int) line: 245
        FrameLayout(View).measure(int, int) line: 7115
        LinearLayout.measureVertical(int, int) line: 464
        LinearLayout.onMeasure(int, int) line: 278
        LinearLayout(View).measure(int, int) line: 7115
        PhoneWindow$DecorView(ViewGroup).measureChildWithMargins(View, int,
int, int, int) line: 2875
        PhoneWindow$DecorView(FrameLayout).onMeasure(int, int) line: 245
        PhoneWindow$DecorView(View).measure(int, int) line: 7115
        ViewRoot.performTraversals() line: 698
        ViewRoot.handleMessage(Message) line: 1482
        ViewRoot(Handler).dispatchMessage(Message) line: 99
        Looper.loop() line: 123
        ActivityThread.main(String[]) line: 3948
        Method.invokeNative(Object, Object[], Class, Class[], Class, int,
boolean) line: not available [native method]
        Method.invoke(Object, Object...) line: 521
        ZygoteInit$MethodAndArgsCaller.run() line: 782
        ZygoteInit.main(String[]) line: 540
        NativeStart.main(String[]) line: not available [native method]


I hope someone can help me out, I know I am missing something here.
Thanks to all in advance!

Thanks
--~--~---------~--~----~------------~-------~--~----~

2. Changing standin animation in camera preview

Hi,

I am working on camera preview. I want to change the standin animation
and want to put my own animation, any idea, how this can be done ??

Thanks
Nithin

--~--~---------~--~----~------------~-------~--~----~

3. savedInstanceState Textview text problem.

4. Custom GridView

5. How can i catch the notification from in built mail in mobile?

6. About Android Email architecture ??

7. How to make my device sleep