I am trying to receive two different intents from two different activity. I tried the approach below in the OnCreate of my receiving activity:
 Intent intent1 = getIntent();
        if(intent1.getStringExtra("packagename").equals("com.example.kaad.calenderlearning.MainActivity")) {
            DateString = intent1.getStringExtra("DATE");
            try {
                DateFormat df = new SimpleDateFormat("MMM d,yyyy", Locale.ENGLISH);
                date = df.parse(DateString);
            } catch (ParseException e) {
                e.printStackTrace();
            }
            DateTextView.setText(DateString);
            save = true;
            correctintent = false;
        }
        else
        {
            Bundle extras = getIntent().getExtras();
            if (extras != null)
            {
                rowID = extras.getLong("row_id");
                AppointmentsEditText.setText(extras.getString("title"));
                LocationNameEdit.setText(extras.getString("location"));
                AppointmentDoctorEdit.setText(extras.getString("doctor"));
                DateTextView.setText(extras.getString("date"));
            }
            if(getIntent().getExtras() == null)
            {
                save = true;
            }
            correctintent = true;
            save = false;
        }
It works when the StringExtra is present in the intent. However, it does not go to the else statement. Instead, it shows the error below:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.kaad.calenderlearning/com.example.kaad.calenderlearning.MakeAppointmentsActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.String.equals(java.lang.Object)' on a null object reference
I have researched on this topic. But none of the solutions worked in my project. I would really appreciate the help of this community.
 
     
    