How to Open a New Activity With a Button in Android Studio [Kotlin 2020]

Поділитися
Вставка
  • Опубліковано 15 вер 2024
  • In this video, you will learn how to open a new Activity from a Button click. This could be achieved with Intent object and pass it to startActivity method. You will also learn how to navigate back to the previous activity by clicking on the back arrow button in the Action Bar. Therefore, you will learn how to update the title in the actionBar and enable arrow back button by setting setDisplayHomeAsUpEnabled method to true.
    🔴 Subscribe for more educational tutorials on CodeWithMazn channel!
    Follow me on Instagram
    / codewithmazn

КОМЕНТАРІ • 78

  • @rawhasan1180
    @rawhasan1180 3 роки тому +93

    For anyone having an error with the newer version of Android Studio, try this:
    val secondActivityBtn: Button = findViewById (R.id.secondActivityBtn)
    secondActivityBtn.setOnClickListener() {
    val intent = Intent(this, SecondActivity::class.java)
    startActivity(intent)
    }
    Thanks for the tutorial Mazn! Keep up the good work!! :)

    • @EricPerez-lj3lf
      @EricPerez-lj3lf 3 роки тому +1

      I already did and it didn't work!

    • @miadudasova5430
      @miadudasova5430 3 роки тому +1

      I did the same and it says
      Unresolved reference: Button
      Unresolved reference: Intent

    • @omarsoutari4808
      @omarsoutari4808 3 роки тому

      @@miadudasova5430 same here

    • @mordechaicayson4287
      @mordechaicayson4287 3 роки тому

      sorry to be so off topic but does any of you know a method to get back into an Instagram account??
      I was stupid forgot the password. I would love any help you can offer me.

    • @Elleozito
      @Elleozito 3 роки тому

      @@mordechaicayson4287 i've the same error than u, i've send like 100 emails and didn't work at all

  • @quasarstories
    @quasarstories 3 роки тому +18

    mine is having error when I am typing the id name to set the click listener. How to fix this?

    • @Hrit
      @Hrit 3 роки тому +1

      create a variable first
      val name : typeofview = findViewById(R.id.view_id)
      name.setOnClickListerner{
      }
      it should work!

  • @lifeforce3451
    @lifeforce3451 2 роки тому

    The way you teach is really nice and relaxing , I am designing my first android app with you.

  • @ulagrech8715
    @ulagrech8715 11 місяців тому

    this is what i exactly wanted!! thank you so much!! God bless you!!!

  • @cristine_l
    @cristine_l 3 роки тому +5

    That was really helpful, thank u!

  • @Hrit
    @Hrit 3 роки тому

    Finally a video that worked! Thank You

  • @77romeromiguel
    @77romeromiguel 2 роки тому +1

    Excelente video, fácil de entender. Saludos desde Venezuela.

  • @djdave4863
    @djdave4863 2 роки тому +1

    Nice one, thank you for the tutorial men.

  • @bbulliard
    @bbulliard 2 роки тому

    Well done! Simple,easy to follow

  • @marcinzale
    @marcinzale 2 роки тому

    Very clear explained. Thanks!

  • @earnzyy9513
    @earnzyy9513 2 роки тому +2

    Can I put 3 Activity in one project?

    • @ArshidAE
      @ArshidAE 2 роки тому +1

      same question here?

  • @Artimer
    @Artimer 2 роки тому

    Fast, smart, clean as I wanted :D

  • @user-xl1xi3ee7r
    @user-xl1xi3ee7r 4 роки тому +1

    Thank you sir .. easier to understand 🤗

  •  3 роки тому

    Click create activity 2 but when click back create activity 1. But don't close activity 1 so create too much activity. When back close app don't execent. Please check.

  • @marc988
    @marc988 2 роки тому

    Thanks ! (Just increase the volume please)

  • @saifaliee
    @saifaliee 3 роки тому

    thank you so much sir, its help me alot...............

  • @IbnFadlan2
    @IbnFadlan2 2 роки тому

    Great work God bless you

  • @anonperson5491
    @anonperson5491 3 роки тому +2

    Quick question. The secondActivityBtn on line 14 of the MainActivity.kt file is red error underlined, saying there is an unresolved reference. Any thoughts on how to fix it? Thanks!

    • @CodeWithMazn
      @CodeWithMazn  3 роки тому +1

      You might missed typed an ID from different layout. Double check on the ID that you are referencing.

    • @muazthunder
      @muazthunder 3 роки тому +1

      same

    • @danieltopatan6189
      @danieltopatan6189 3 роки тому

      Same

  • @franciscoma.alexandrar.7469
    @franciscoma.alexandrar.7469 2 роки тому

    Hello... how can i remove the action bar? Because I planned to put a new action bar from other resources... thank you...

  • @iqrairshad9553
    @iqrairshad9553 3 роки тому

    we apply the tab layout and navigation drawer first and then wanna apply second activity by clicking button. But when we run the app after applying the intent code its not working. So plz can u tell me where we can add the second activity code in java file?

  • @ahmedazmi5297
    @ahmedazmi5297 2 роки тому

    Highly recommend him

  • @DezzyPie123
    @DezzyPie123 2 роки тому

    Set this up in my code, but it didn't provide the functionality I was looking for. Upon removing the code the back button is still displaying? Anyone have any ideas how to remove it so as not to cause confusion?

  • @M13S
    @M13S 3 роки тому

    Thank you man great job.

    • @CodeWithMazn
      @CodeWithMazn  3 роки тому +1

      I am glad that you liked it. More contents are coming soon! Stay tuned!

  • @DeepakPrajapati-lj1rf
    @DeepakPrajapati-lj1rf 3 роки тому

    Thanks mate!

  • @theodorestsm5393
    @theodorestsm5393 3 роки тому

    I have tried this and the program does not see the 'this,' it wants a variable

  • @ellyjessy5044
    @ellyjessy5044 2 роки тому

    Thank you so much

  • @immortalmonsterhybrid975
    @immortalmonsterhybrid975 3 роки тому +2

    welp this didnt work for me it seems

  • @facttv4405
    @facttv4405 3 роки тому

    Thank you

  • @node3079
    @node3079 3 роки тому

    thank uu!

  • @raulgenaroadamenajera6663
    @raulgenaroadamenajera6663 3 роки тому

    ¡Muchas gracias!, funciona de maravilla :D

  • @ferryman7493
    @ferryman7493 4 роки тому

    Good

  • @user-gj9vy7gy8y
    @user-gj9vy7gy8y 3 роки тому

    Hi sir, why the Button's ID is not showing out on my MainActivity page even if I typed it correctly?

    • @CodeWithMazn
      @CodeWithMazn  3 роки тому

      Double check your main xml file. You might referencing an ID from a different layout file!

    • @sayyidj6406
      @sayyidj6406 3 роки тому +4

      val "your button id" = findViewById(R.id."your button id") as Button
      after your call your button, then just type button id in your activity and continiu the tutor
      i spent a hours to solve this
      i am not englishman, cant speak english properly

    • @arjunvarma9350
      @arjunvarma9350 2 роки тому

      @@sayyidj6406 english doesnt matter brother you saved me hours thank you

    • @sayyidj6406
      @sayyidj6406 2 роки тому

      @@arjunvarma9350 well, you might want to learn flutter with android studio, its better workplace, use dart as universal language, which single code can export to android, ios, web even windows app, check its ok bro its worth it (with kotlin or java u need to rewrite your code for ios)

  • @omarsoutari4808
    @omarsoutari4808 3 роки тому

    it doesn't work ...

  • @llhero3671
    @llhero3671 2 роки тому

    Not working 😢

  • @ragavendhiran8341
    @ragavendhiran8341 2 роки тому

    ❤❤❤🧡😀😀✌👌👌👌

  • @EricPerez-lj3lf
    @EricPerez-lj3lf 3 роки тому

    val button = findViewById(R.id.button)
    button.setOnClickListener{
    val intent = Intent(this,SecondActivity::class.java)
    startActivity(intent)
    }
    it gives me error anyway I type it, I don't know what to do. And no one in the entire web gives me an explanation for that. I think maybe if I offer big money to solve this issue someone might help me. I don't really know exactly what solution to take.

  • @ayushjha7589
    @ayushjha7589 4 роки тому +2

    Good (don't reply)

  • @AliciaDH
    @AliciaDH 3 роки тому

    If possible can you use java instead of kotlin for this. If not how would it be used in java
    btnAllTasks.setOnClickListener{
    val intent = Intent(packageContext this, show all tasks::class.java)
    startActivity(intent)

    • @CodeWithMazn
      @CodeWithMazn  3 роки тому

      Yes, you can use Java and I believe its the same for creating Intent! Check my firebase tutorial series! I am using Intent in Java!

  • @atzinvargasmorales5278
    @atzinvargasmorales5278 3 роки тому +2

    to everyone who is strugglin in 1:50 here is the solution, just follow the steps ua-cam.com/video/XwxUovb4Rwk/v-deo.html

  • @codingcrush
    @codingcrush 3 роки тому +1

    unresolved reference: secondActivityButton

  • @anurajms
    @anurajms 3 роки тому

    thank you

  • @faaris2394
    @faaris2394 3 роки тому

    i dont get "packageContext" pop up,How to solve this ?

    • @danwhelan
      @danwhelan 3 роки тому

      Did you solve this?