Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9127909
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T07:23:38+00:00 2026-06-17T07:23:38+00:00

I have an activity 1 which send intent to activity 2 as bellow: activity

  • 0

I have an activity 1 which send intent to activity 2 as bellow:

activity 1

periodDatetv.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub

                Intent i = new Intent(Settings.this, SettingsPeriodDate.class);
                startActivityForResult(i, 100);
            }
        });

activity 2

@Override
    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        todayCalendar = new GregorianCalendar();
        pickedDateCalendar = new GregorianCalendar();
        final Dialog dialog = new Dialog(SettingsPeriodDate.this);
        dialog.setContentView(R.layout.perioddatesettings);

        datePicker = (DatePicker) dialog.findViewById(R.id.DataPickerDate);

        dialog.show();

        Button okDialogButton = (Button) dialog
                .findViewById(R.id.dialogButtonOK);

        // if button is clicked, close the custom dialog
        okDialogButton.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {

                Calendar c = Calendar.getInstance();
                int currentYear = c.get(Calendar.YEAR);
                int currentMonth = c.get(Calendar.MONTH) + 1;
                int currentDay = c.get(Calendar.DAY_OF_MONTH);

                Day = datePicker.getDayOfMonth();
                Month = datePicker.getMonth() + 1;
                Year = datePicker.getYear();

                todayCalendar.set(currentYear, currentMonth, currentDay);
                pickedDateCalendar.set(Year, Month, Day);

                System.err.println("Choseon date = " + Day + "/" + Month + "/"
                        + Year);
                System.err.println("Today date = " + currentDay + "/"
                        + currentMonth + "/" + currentYear);

                int Days = daysBetween(todayCalendar.getTime(),
                        pickedDateCalendar.getTime());

                System.err.println("Daaaaays === " + Days);

                if (pickedDateCalendar.after(todayCalendar) || Days >= 1) {
                    System.err.println("Inside if pop it");
                    PopIt("Error ", "Please check the date again");

                }

                else {

                    periodDateSharedPreferences(Year, Month, Day);

                }
                dialog.dismiss();
                System.err.println("befor back");
                Intent saved2 = new Intent(SettingsPeriodDate.this,
                        Settings.class);
                startActivityForResult(saved2, 100);


            }

        });

        Button cancelDialogButton = (Button) dialog
                .findViewById(R.id.dialogButtonCancel);
        // if button is clicked, close the custom dialog
        cancelDialogButton.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
                Intent i = new Intent(SettingsPeriodDate.this,Settings.class);
                startActivity(i);
            }
        });

    }

    public int daysBetween(Date d1, Date d2) {
        return (int) ((d2.getTime() - d1.getTime()) / (1000 * 60 * 60 * 24));
    }

    public void periodDateSharedPreferences(int calculatedPeriodYear,
            int calculatedPeriodMonth, int calculatedPeriodDay) {
        SharedPreferences periodDatePreferences = PreferenceManager
                .getDefaultSharedPreferences(this);
        SharedPreferences.Editor editor = periodDatePreferences.edit();
        editor.putInt("periodChosenDay", calculatedPeriodDay);
        editor.putInt("periodChosenMonth", calculatedPeriodMonth);
        editor.putInt("periodChosenYear", calculatedPeriodYear);
        editor.commit();

        System.err.println("periodChosenDay preferences"
                + periodDatePreferences.getInt("periodChosenDay", 0));
        System.err.println("periodChosenMonth preferences"
                + periodDatePreferences.getInt("periodChosenMonth", 0));
        System.err.println("periodChosenYear preferences"
                + periodDatePreferences.getInt("periodChosenYear", 0));
        Toast.makeText(SettingsPeriodDate.this, "The date was saved",
                Toast.LENGTH_LONG).show();

        finish();
    }

    public void PopIt(String title, String message) {

        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle("Error");
        builder.setMessage("Please check again");
        builder.setCancelable(true);

        final AlertDialog dlg = builder.create();

        dlg.show();

        final Timer t = new Timer();
        t.schedule(new TimerTask() {
            public void run() {
                dlg.dismiss();
                t.cancel();
            }
        }, 100000);
    }

and I get the result in activity 1 as bellow :

public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        switch (requestCode) {
        case 100:
            System.err.println("after intent back 111111=== ");

             if (resultCode == Activity.RESULT_OK) {
            System.err.println("after intent back if=== ");

            int day = data.getIntExtra("Day", 0);
            int month = data.getIntExtra("Month", 0);
            int year = data.getIntExtra("Year", 0);
            System.err.println("after intent back =///== " + day + "-" + month
                    + "-" + year);
            Toast.makeText(Settings.this,day+"?"+month+"?"+year,Toast.LENGTH_SHORT).show();
            periodDatetv.setText(day + "/" + month + "/" + year);
            break;

         }

        }
    }

But it never runs the onActivityResult method ! what is the wrong in my code ? please tell me .. and thanks in advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T07:23:39+00:00Added an answer on June 17, 2026 at 7:23 am

    use setResult(RESULT_OK); before finish() method from second activity

    from the second activity which you want should return some result to first activity

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an activity which send a data to another activity using intent as
I have registered my activity in the manifest as android.intent.action.SEND. Now, after pressing SHARE
At this moment I have activity (lview) with list view which use images downloaded
I have an Alarm Manager which send Intent to BroadcastReceiver. This Broadcast is not
I have a BroadcastReceiver that I'm using to send data to another activity which
I have an activity which is going to switch around between several views, and
I have a activity which has a button and 2 autocomplete widget. for the
I have an Activity which shows a welcome message if started for the first
I have an activity which shows some List entries. When I click on a
I have an activity which needs to make two remote server calls. The first

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.