January 28, 2021

How to Make a Button Open a New Activity – Android Studio Tutorial



In this video we will learn, how to open a new Activity from a Button click. For this we will create a new Intent and pass it to the startActivity method.

Example code for this video:

____________________
❗ Subscribe to the channel:

⏯ Watch more tutorials:

⭐ Become a channel member for exclusive tutorials and other perks:

㊙ Help translating the videos:

💚 Support the content:

💬 Join the Discord chat:

🎧 Audiobooks and podcasts for programmers:

👶 How to get started with Android development:

📣 Follow Coding in Flow on social media:

Facebook:

Instagram:

Twitter:

Blog:

Nguồn: https://sam-pointer.com/

Xem thêm bài viết khác: https://sam-pointer.com/cong-nghe/

Related Posts

How To Install MySQL on Windows 10

July 16, 2020

July 16, 2020 44

In this post we will learn how to How To Install MySQL on Windows 10. The same procedure can be...

Churrasquinho do Menos é Mais – Manda Áudio (part. Di Propósito)

July 15, 2020

July 15, 2020 20

Churrasquinho do Menos é Mais – Manda Áudio Participações: Di Propósito e Grupo Vou Zuar Thiago Viégas: direção e produção...

Hướng dẫn tải và cài đặt StarCraft II The Complete Collection Full Crack 2019 – Daominhha.com

July 11, 2020

July 11, 2020 5

Tải game StarCraft II The Complete Collection miễn phí Google Drive, Hướng dẫn cài đặt StarCraft II The Complete Collection...

StartIsBack 2.8 full version plus license key (Activated)

July 11, 2020

July 11, 2020 31

This tutorial will show You How to install and Activated StartIsBack(start is back) 2.8 full version Also show you how...

Sửa Lỗi Không Mở Được Start Menu Trên Windows 10

July 14, 2020

July 14, 2020 44

(các bạn nhấn “hiện thị thêm” hoặc “show more” để xem những cách khác nhé!) Nút Start trên Win 10...

Starcraft Free Full Version Brood War (Download How to and Where Guide; Sci-Fi RTStrategy Game)

July 14, 2020

July 14, 2020 6

Starcraft – Download the free full version and its expansion Brood War. (They are now downloadable full version freeware.) Instructions...

FPT Shop – Samsung Galaxy S9+ đối đầu iPhoneX | Tin Công Nghệ Hot Số 97

July 15, 2020

July 15, 2020 4

FPT Shop – Samsung Galaxy S9+ đối đầu iPhoneX, Mimix 2S sẽ không có tai thỏ | Tin Công Nghệ...

Hướng dẫn chi tiết cách cài Win 8.1 bằng USB (Windows 8.1 Pro)

July 14, 2020

July 14, 2020 24

Hướng dẫn cách cài Win 8.1 bằng USB chi tiết từng bước một. Bạn chỉ cần chuẩn bị 1 cái...

How to bring back the Start Menu in Windows 8.1 / Windows 8

July 11, 2020

July 11, 2020 37

How To Get The Windows 8 Start Menu Get the Classic Start Menu on Windows 8.1 | Classic Shell Install...

Another Decent Unknown ssd? Silicon Power S55

July 7, 2020

July 7, 2020 25

Today we take a look at another decent unknown ssd that has 1 major floor Grab an S55 drive here:...

Basico: Aprende a diferenciar los SSD | Western Digital SSD – Proto Hw & Tec

July 13, 2020

July 13, 2020 44

Nuestras computadoras LEGA de venta Aqui: *Correo para cotizaciones de armados de PC* **** proto.tec2015@gmail.com **** **** ventas@highpro.com.mx **** ——————————————–...

Free download StarCraft – Brood War REMASTERED [PC/MAC]

July 16, 2020

July 16, 2020 1

How to Free download StarCraft – Brood War REMASTERED [PC/MAC]? Check this link with crack and full game: Have fun...

WD Blue SN550 – SSD M.2 PCIe quá nhanh, quá ổn trong tầm giá!

July 9, 2020

July 9, 2020 28

WD Blue SN550 là dòng SSD M.2 PCIe phổ thông với ưu điểm về hiệu năng/giá. SN550 thay thế cho...

Đánh giá nhanh SSD WD Blue SN550: SSD M.2 NVMe giá tốt hiệu năng bất ngờ!

July 15, 2020

July 15, 2020 2

WD Blue SN550 là dòng SSD phổ thông được đánh giá có hiệu năng/ giá thành rất tốt thời điểm...

Round Rubber Stamp Design in MS Word, Self ink Stamp kaise banaye, how make to rubber stamp, jm

July 13, 2020

July 13, 2020 15

rubber stamp in ms word, design in ms word, rubber stamp kaise banaye, self ink stamp kaise banaye, stamp ki...

Comments
  • Very Nice and concise video. Well Done!
    I was wondering what code changes would be needed if you had two or buttons on the same page or in a list.
    Thanks for taking the time to develop this.

  • intent intent new intent intent activity intent intent
    bro just use some different words someone like me who is new to java wont get it

  • Upon clicking I get the generic "Unfortunatley, the app has stoped working" error. My repo is different than yours but I've copied your steps:
    https://github.com/Zemogiter/AmaWeatherApp
    Any help?

  • For the button.OnClickListener(), the button shows as expected class or package, how do I resolve it?

  • I had a problem, it says "AAPT: error: resource string/action_settings (aka com.example.myapp:string/action_settings) not found."
    In particulary it's missing the main.xml:4…. I only had content_main and actvity_main… I didn't have main
    what should I do? I didn't use your code, but I needed to make the button open another activity
    Please, help me

  • hii your video is very useful and easy to understand!!

    can i ask a question, so im making expert system on android studio, how can i make the button open another activity? so i can open multiple activitu with just one button

  • package com.example.application.myapplication;

    import android.content.Intent;

    import android.support.v7.app.AppCompatActivity;

    import android.os.Bundle;

    import android.view.View;

    import android.widget.Button;

    public class MainActivity extends AppCompatActivity {

    private Button button;

    @Override

    protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_main);

    button = (Button) findViewById(R.id.button);

    button.setOnClickListener(new View.OnClickListener() {

    @Override

    public void onClick(View v) {

    openActivity2();

    }

    });

    }

    public void openActivity2() {

    Intent intent = new Intent(this, Activity2.class);

    startActivity(intent);

    }

    }

  • For more info on intents and how to pass data from one activity to another watch this:-
    https://youtu.be/BY5MtRrAMP8

  • Hi, thanks for the video first up! I'm having a slight problem though. I try to open another activity having google map in it, and it briefly opens for a second, after which it closes and says "App keeps stopping". What should I do? Please help!

  • I can't edit the activity_main_XML file…even copy & paste also not working inside the file..can u help me pls

  • Uncaught TypeError: Cannot read property 'update' of undefined

    this is the error im facing . the app keeps on crashing as soon as i press the button

  • Sehr gutes Video danke wieder dafür, doch wieso änderst du in der xml Datei das Layout immer in Relative ?

  • This is my xml_main

    <ImageButton
    android:id="@+id/btn2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginBottom="344dp"
    android:background="@drawable/ic_poule1"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.498"
    app:layout_constraintStart_toStartOf="parent" />

  • I have used but the button desapears when i click on.
    public class MainActivity extends AppCompatActivity {
    ImageSwitcher btn2;
    int mDefaultColor;
    @SuppressLint("WrongViewCast")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mDefaultColor = ContextCompat.getColor(MainActivity.this,R.color.colorAccent);
    btn2 = findViewById(R.id.btn2);
    btn2.setOnClickListener(new View.OnClickListener() {
    @RequiresApi(api = Build.VERSION_CODES.M)
    @SuppressLint("ResourceType")
    @Override
    public void onClick(View v) {
    openColorPicker();

    }
    });
    }
    public void openColorPicker(){
    AmbilWarnaDialog colorPicker = new AmbilWarnaDialog(this, mDefaultColor, new AmbilWarnaDialog.OnAmbilWarnaListener() {
    @Override
    public void onCancel(AmbilWarnaDialog dialog) {

    }

    @Override
    public void onOk(AmbilWarnaDialog dialog, int color) {
    mDefaultColor = color;
    btn2.setBackgroundResource(R.drawable.ic_poule1);
    btn2.setBackgroundColor(color);
    //btn2.R.drawable.ic_poule1.setColor(color);

    }
    });
    colorPicker.show();
    }
    }

  • Hi, I wonder the changing of background tint, size, margins of the buttons will affect the function of the button? Cuz I followed what you showed it works at first, but after I changed the background tint and margin all that minor changes it turns out buttons did not show in the emulator…i need help…

Leave a Reply

Your email address will not be published. Required fields are marked *