This code might help you..
 public void onCreate(Bundle savedInstanceState)
            {
         super.onCreate(savedInstanceState);
     setContentView(R.layout.search);
     Button b2=(Button)findViewById(R.id.button1);

     b2.setOnClickListener(new View.OnClickListener() {

         public void onClick(View v) {
             Intent intent=new Intent(v.getContext(),MainPage.class);
             startActivity(intent);
     }});

 in another class:
 Button b=(Button)findViewById(R.id.Button);

                b.setOnClickListener(new View.OnClickListener() {

                        public void onClick(View v) {
                                         Intent intent=new
Intent(v.getContext(),Search.class);
                                                     
startActivityForResult(intent,0);
                        }  });
            }

On Aug 2, 8:15 pm, Shabu Thomas <[email protected]> wrote:
> In my application,  activity A is the default one and I have created
> another activity B. There is a button in each activity. On click event
> of the button, the other activity should be brought to front. So, for
> the first click, the activity will be created (OnCreate will be
> called) and for the subsequent clicks, new instances should not be
> created but it should be brought to front only (OnNewIntent should be
> called).
>
> Button click of Activity B will do the same. But, when we click the
> button on A, instead of calling OnNewIntent of B, OnCreate will be
> called which means B will again be created. How can we avoid it?
>
>    public void OnMyButtonClickOfA(View view)
>     {
>                    Intent i = new Intent(this, B.class);
>                    i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP |
> Intent.FLAG_ACTIVITY_SINGLE_TOP ); // What should I do here in order
> to avoid the recreation of B?
>
>                 i.putExtra("string", "Again Called");
>                         startActivity(i);
>
>     }
>
>     public void OnMyButtonClickOfB(View view)
>             {
>                 Intent intent = new Intent(this, A.class);
>                 intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP |
> Intent.FLAG_ACTIVITY_SINGLE_TOP );
>                 //intent.putExtra("MyClass", m);
>                 intent.putExtra("string", "Recalled");
>                 startActivity(intent);
>
>             }

-- 
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

Reply via email to