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

  • SEARCH
  • Home
  • 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 8654391
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T14:46:35+00:00 2026-06-12T14:46:35+00:00

I am developing sample a android app having three activities named Stationary, Books and

  • 0

I am developing sample a android app having three activities named Stationary, Books and Pens. I want to send data from Books and Pens activities to Stationary activity. In Stationary activity when I receive data from one activity either Books or Pens it works fine but when I receive data from both the activities my app “Stop Unexpectedly”

I have developed some code in this respect you can check it below.

in my Book activity am using the following code.

    // in Book Activity
public boolean onKeyDown(int keyCode, KeyEvent event) 
     {
         if ((keyCode == KeyEvent.KEYCODE_BACK))
         {  



                if(myBookSelected)
                {   
                Intent intent = new Intent(Books.this,Stationary.class);
                intent.putExtra("bookSelected", books.toString());
                startActivity(intent);
                }

                else
                {
                    Toast.makeText(getApplicationContext(), "Please select books", Toast.LENGTH_LONG).show();
                }

          }

         return true;
     }

and in my Pens Activity am using the flowing code.

// in Pen Activity
public boolean onKeyDown(int keyCode, KeyEvent event) 
     {
         if ((keyCode == KeyEvent.KEYCODE_BACK))
         {  



                if(myPenSelected)
                {   
                Intent intent = new Intent(Pens.this,Stationary.class);
                intent.putExtra("penSelected", pens.toString());
                startActivity(intent);
                }

                else
                {
                    Toast.makeText(getApplicationContext(), "Please select Pens", Toast.LENGTH_LONG).show();
                }

          }

         return true;
     }

To receive data in Stationary activity from the above two activities that is Books and Pens. I am using the following code.

// in Stationary Activity
Bundle extras = getIntent().getExtras();


            if (extras != null)
            {   
                numberOfBooks = extras.getString("bookSelected");
                numberOfPens = extras.getString("penSelected");
            }

NOTE: When I receive data from one activity either Books or Pens it works fine but when I receive data from both the activities my app “Stop Unexpectedly”

  • 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-12T14:46:36+00:00Added an answer on June 12, 2026 at 2:46 pm

    its because when you try to pass a Intent from your BookActivity your "penSelected" will be null and in the other case "bookSelected" will be null. So obviously you will hit NullPointerException here.

    A simply nasty solution will be to surround them in separate try catch blocks. Or you might have to send another data to identify from which Activity you are being passed and based on that get only the required field.

    Say for example you come from PenActivty then you could get only "penSelected" and leave the other one and vice versa.

    So what you have to understand here is, in neither of the cases your object "extras" wont be null , but only any one of the above key will be null. So you can’t check for null there.

    EDIT

    i believe it is not true after all. You can check whether the Bundle Oject contains the key or not using the below code,

     if(getIntent().hasExtra("bookSelected"))
    {
             // do your code.. 
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am developing an Android App that gets some data from a web server,
I am developing a simple sip-based voip app for android. I used this sample
I'am developing a sample push notification app in android using c2dm. Here is my
I am developing an in app billing application for Android In this sample ,
I'm developing simple video recording app for Android 2.2+ and having trouble with getting
I have tried developing a sample app with the help of the code from
I am developing an android app in which I have 3 spinners populated from
I'm developing a sample app for android and my level is beginner. For simplicity
I am currently developing my program using sample BluetoothChat program on android device. This
Am developing a sample application for some administration activities. I need to know how

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.