May 7, 2021

Send Data Back from Child Activity with startActivityForResult – Android Studio Tutorial



When we open another activity, we can send data to it by using an intent and putExtra. But what if we also want to get something back? This is what the startActivityForResult method is for. By opening our child activity with this method and overriding onActivityResult we can send data back to our parent activity after we set it with setResult in our child activity before we close it.

Source code:

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

Guide On HOW To Design & Create The PERFECT Farm Layout – Stardew Valley 1.3

July 11, 2020

July 11, 2020 24

●FOLLOW me on twitter ready for my new upcoming competition! ➤twitter.com/gamesharkyt ●Design Your Own Farm Using Stardew Valley Planner! ➤stardew.info/planner/...

How to install the WD Blue 500GB SSD into your computer #WDBlueSSD

July 15, 2020

July 15, 2020 24

✅Check it out on Amazon: Check out my quick video on how to install the WD Blue 500GB SSD 6Gb...

New Mercedes S-CLASS (2021) – CRAZY INTERIOR tour (digital cockpit, new MBUX, 3D head-up display)

July 8, 2020

July 8, 2020 24

Taking a look at the official Mercedes footage of the all new 2021 Mercedes S-Class W223! The interior is technological...

SSD vs HD – PC muito mais rápido (Sandisk Plus)

July 14, 2020

July 14, 2020 30

Deixe seu PC muito mais rápido utilizando um SSD. No vídeo mostro minha experiência com o SSD Sandisk Plus, veja...

Lắp thử SSD NVME Samsung 970 Evo và cái kết không ngờ ! |GCN Store

July 7, 2020

July 7, 2020 2

Trong clip ngày hôm nay mình sẽ khui hộp con SSD NVME Samsung 970 Evo để chạy thử ! aem...

Hướng Dẫn Cài Đặt SSL/HTTPS Miễn Phí Từ Host sử dụng CPanel cho web WordPress | Công Việt Blogger

July 13, 2020

July 13, 2020 5

Hướng Dẫn Cài Đặt SSL/HTTPS Miễn Phí Từ Host sử dụng CPanel cho web WordPress | Công Việt Blogger Website:...

⭐️STAR APPLE Caimito Taste Test | Fruity Fruits

July 13, 2020

July 13, 2020 46

Star apples are native of the West Indies and when sliced in half, display a beautiful star. Let’s find out...

MySQL – Remote Access to MySQL Server on Linux CentOS 6.3 Part 1

July 14, 2020

July 14, 2020 26

In this tutorial I talk you through installing and configuring a MySQL server to allow remote access on Linux using...

Mua Hàng Online Gia Rẻ 500k ssd 120gb Và Cái Kết

July 13, 2020

July 13, 2020 44

Đăng ký kênh miễn phí ( Subscribe free) : Đăng ký kênh phụ dự phòng ae nhé : Pc 20tr...

How to Make Windows 10 looks like Windows 7

July 14, 2020

July 14, 2020 42

On this video I’m gonna show you how to make your windows 10 computer looks like windows 7 computer. ✅...

Starcraft 2 Indonesia Free to Play Download Gratis Main Starcraft

July 16, 2020

July 16, 2020 10

Starcraft 2 going free to play how to download.. Download Link dibawah ini.. Starcraft 2 gratis download dan bermain.. Sampai...

Hướng dẫn thay đổi nút Start trên Windows 10 và windows 7

July 14, 2020

July 14, 2020 16

Video: Hướng dẫn thay đổi nút Start trên Windows 10 và windows 7 Serri các video thủ thuật máy tính...

[Review] Mua được ổ cứng SSD giá rẻ 400k và cái kết quá ngon

July 9, 2020

July 9, 2020 2

– Mình chạy win 10 toàn bị lỗi full disk 100% nên quyết đinh đầu tư mua 1 cái ổ...

HOW TO KNOW WHO STALK TO YOUR FACEBOOK PROFILE 2019

July 15, 2020

July 15, 2020 21

OCTOBER 2019 HOW TO KNOW WHO STALK TO YOUR FACEBOOK PROFILE 2019 Get P50 for FREE when you sign-up to...

[MV Ca nhạc] Màn cầu hôn ngọt ngào tại Star Galaxy và cái kết…

July 16, 2020

July 16, 2020

MÀN CẦU HÔN NGỌT NGÀO TẠI STAR GALAXY VÀ CÁI KẾT… Cách đây hơn 3 năm chàng trai Phùng Cường...

Comments
  • I do not understand why this case needs to handle the activityResult? why can't I putExtra different values in the add and the sub-struct and use in the mainActicity regular Intent with getIntent?

  • Hi, Is it possible to multiply editText to TextView?
    sample below
    ditText editText = findViewById(R.id.editText);

    TextView textView46 = findViewById(R.id.textView46);

    // this is the result to activity2
    TextView result10textView25 = (TextView) findViewById(R.id.textView25);

    this is the computation
    int num1 = Integer.parseInt(editText.getText().toString());

    int num46 = Integer.parseInt(textView46.getText().toString());
    int result10 = num1 * num46;

    result10textView25intent.putExtra(name.”resullt10”, result10);

    Current is not working

  • If I wanted to have an edittext that I wanted the user to input the number they think was the right value for result and then count up by 1 if they get it right and stay where it's not right. How would I do that? Say (number 1 + number 2 is -> 2 + 1 = 3) on the other activity I have an edittext that I input 3 will be the result. Then I need a counter for every time I get it right? So for example first wave (2 + 1 = 3) I input 3 counter = 1. second round through (3 + 4 = 7) I input 7 counter = 2. Third round (4 + 3 = 7) I input 6 so counter = 2. How do you do that?

  • The only channel which provides crystal clear concept in android development kudos to you

    Coding in Flow thanks for making programmer life easy <3

  • When programmers face a problem, they usually google it. Now as I know you, when i bump into a problem I can "coding in flow" it.

  • thanks a lot!
    please tell me how to pass another object (other than int as in the video) as i want to return a self defined object..
    Thanks!!!

  • I appreciate your videos but can you please try to use more of an American or British accent? Very difficult to understand many parts. What is being said at 7:05? "We know that the input is ___" ??

  • Hi guy, thanks for all your amazing tutorials… I have received so many answers to issues from them… please explain, this is for an int what if you want to retrieve a String value… I have a class that updates FirebaseDatabase and I want the String to be passed from the child activity to main: I followed your example and passed:
    Intent resultIntent = new Intent();
    resultIntent.putExtra("names",name);

    setResult(RESULT_OK, resultIntent);
    ….. but in the MainActivity, under onActivityResult, how to I retrieve the String???

    Thanks a lot !!

  • Great job, I have startActivityForResult it works great but in some device when i com back from child activity then the parent activity become recreate (It means that the parent Activity start again) this happen in SAMSUNG Glaxy A3, please help me if you know something.
    I searched a lot about that but couldn't find any solution, someone says that it's because low memory.

  • How do we use this to change an EditText's text when back button is pressed and we return from the second activity to the first activity again? the EditText is in the first activity.

  • PLEASEEE please could you explain what is a CIRCULAR INTENT and how to avoid it? I failed my Android exam because the professor said that it was wrong to use startActivity(intent) and I should have used startActivityForResult and onActivityResult. But I don't really undesrtand in what situations you can't use startActivity(intent) and you have to use the other method. Also, if you use startActivity(intent) and send data through intent with putExtra and then call finish() and then in the second activity I also call startActivity(intent) then send data then call finish() is it the same as using startActivityForResult and OnActivityResult?

Leave a Reply

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