• Skip to main content
  • Skip to primary sidebar
  • Skip to footer
  • About
  • Life
  • Tech
  • Travel
  • Work
  • Questions
  • Contact

Welcome

.

Data return from Multiple Activities to Main Activity

April 10, 2020 by

Questions › Data return from Multiple Activities to Main Activity
0
Vote Up
Vote Down
Garmaine asked 3 years ago

everyone. I have started to write(1-month-old) Android apps and I am pretty new this stuff.

I have a activity X. On that activity X, I have four different buttons calls four different activities. On those three activities, I have button, and I am returning data to activity X after I pressed button. Also, on the activity X, I may not call all three of the activies. I might call just 1,3 or just 2,3. I have looked a lot but I could not find what I seek for.

EDIT: when I put finish();to activity 1,2,3, I could call one of the activies(assume activity one called) and able to grab data, and returns the Activity X, but when I started to call other one (assumed activity 2 called), I could go to this activity, but I cannot return from it since it does know where to return.

This is what I seek for:

Activity X-> 1st activity -> return data1 to X

Activity X-> 2nd activity -> return data2 to X

Activity X-> 3rd activity -> return data3 to X

Activity X-> send data1 + data2 +data3 to 4th activity

I started my three activities on Activity X like this under onClick method (data_global is global on Activity X class)

case R.id.btn1:
       Intent i = new Intent(this, Activity1.class);
       startActivityForResult(i, 200);
       break;
case R.id.btn2:
       i = new Intent(this, Activity2.class);
       startActivityForResult(i, 201);
       break;
case R.id.btn3:
       i = new Intent(this, Activity3.class);
       startActivityForResult(i, 202);
       break;
case R.id.btn4:
       i = new Intent(this, Activity4.class);
       i.putExtra("Extra", data_global);
       startActivity(i);
       break;

I take my data from here on Activity X under onActivityResult method:

switch (requestCode) {
        case (200): {
            if (resultCode == Activity.RESULT_OK) {
                if (data.getStringExtra("Extra1").length() != 0) {
                    data_global += data.getStringExtra("Extra1");
                }
            }
            break;
        }
        case (201): {
            if (resultCode == Activity.RESULT_OK) {
                if (data.getStringExtra("Extra2").length() != 0) {
                    data_global += data.getStringExtra("Extra2");
                }
            }
            break;
        }
        case (202): {
            if (resultCode == Activity.RESULT_OK) {
                if (data.getStringExtra("Extra3").length() != 0) {
                    data_global += data.getStringExtra("Extra3");
                }
            }
            break;
        }

And any of activity 1 or 2 or 3 code is like that:(X is at the end on Extra referring to 1,2,3)

case R.id.btnSave:
            Intent resultIntent = new Intent();
            resultIntent.putExtra("ExtraX", "name");
            setResult(Activity.RESULT_OK, resultIntent);
            finish();
            break;

How can I solve my problem? Many thanks.

Are you looking for the answer?
Original Question and Possible Answers can be found on `http://stackoverflow.com`

Question Tags: android, android-activity, java

Please login or Register to submit your answer




Primary Sidebar

Tags

Advancements architecture beautiful life best building calling city commercial convenience employment Finances Cognitive decline Future gadgets Hidden Gems highway Home houses hydration Impact Innovations lamp lighting Mental health military tech Must-See New York City occupation Productivity recreation romance sepia shopping sippy cups smartphones social Technological breakthroughs technology toddlers Treasures turns Uncover Well-being Wonders Work Young onset dementia

Newsletter

Complete the form below, and we'll send you all the latest news.

Footer

Footer Funnies

Who knew that reading the footer could be such a hilarious adventure? As we navigate websites, books, and documents, we often stumble upon the unassuming space at the bottom, only to discover a treasure trove of amusement. In this side-splitting compilation, we present 100 jokes that celebrate the unsung hero of content – the footer. Get ready to chuckle, giggle, and maybe even snort as we dive into the world of footnotes, disclaimers, and hidden comedic gems. Brace yourself for a wild ride through the footer!

Recent

  • Unveiling the Enigma: Almost-Magical Lamp Lights Highway Turns
  • The Impact of Young Onset Dementia on Employment and Finances: Optimizing Post-Diagnostic Approaches
  • 11 Wonders of 2023 Technological Breakthrough – Unveiling the Future
  • Work from Home and Stay Mentally Sane – Achieve Productivity and Well-being
  • Hidden Gems of New York City – Uncover the Must-See Treasures!

Search

Tags

Advancements architecture beautiful life best building calling city commercial convenience employment Finances Cognitive decline Future gadgets Hidden Gems highway Home houses hydration Impact Innovations lamp lighting Mental health military tech Must-See New York City occupation Productivity recreation romance sepia shopping sippy cups smartphones social Technological breakthroughs technology toddlers Treasures turns Uncover Well-being Wonders Work Young onset dementia

Copyright © 2023