Thursday, December 8, 2011

How to redirect to another window in android when button click

This Sample Code explain how to show another window of given url when button click in android.

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class MainWindowActivity 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.button1);    

    button.setOnClickListener(new OnClickListener() {
      public void onClick(View arg) {
        Intent viewIntent =
          new Intent("android.intent.action.VIEW",
            Uri.parse("https://google.com"));
          startActivity(viewIntent);
      }
    });
}
}

2 comments:

  1. Good start!
    I saw your posts in stack overflow too,
    Wish you all the best for your Programming Career :),

    - A Friend

    ReplyDelete
  2. https://play.google.com/store/apps/details?id=com.igeniusdev.valentinecard

    ReplyDelete