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 7624427
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T04:57:43+00:00 2026-05-31T04:57:43+00:00

In an application I’m currently working on I have my first activity with a

  • 0

In an application I’m currently working on I have my first activity with a ListView which is populated from an ArrayList saved to the apps internal memory. Either by using the menu button to select ‘Add’ or by tapping an existing item in the menu I can get to my second activity which is an edit page.

In the first activity if the Add button is pressed, there are no extras passed in the intent and no fields (text boxes, etc) need to be filled in the edit activity. If an existing item is clicked in the first activity, this passes the row ID of that item as an extra in the Intent, with the key string as “_id”.

I understand that *Bundle.getLong(“_id”);* should return null if no extra has been passed with the intent. My problem is that for some reason, getLong() is always returning 0. I tried putting some gibberish as the key string for getLong() but it still returns 0. Has anyone come across this problem before?

I would also like to add that I have two other sets of activities similar to this, using the same method to get the rowId if it has been passed, and they all work fine.

I haven’t been able to find any common problems that might cause this. Thanks in advance for any help.

[EDIT]

Apologies for any confusing and not showing this code previously. As a few people have commented getLong will return 0 if it cant find anything, however the code I use sets mRowId to null if this is the case, or at least I assume it does. This bit kinda confused my but it seemed to work when no other extra was passed with the intent.

mRowId = extras != null
? extras.getLong("_id")
: null;

I also had another mess around and found that if any extra value is passed with the intent (regardless of its key) it will cause it to return 0 rather than null. I assume this code doesn’t work if another extra is passed. If that is the case is there a better way to pass the rowId if necessary and set it as null if nothing is passed.

  • 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-05-31T04:57:44+00:00Added an answer on May 31, 2026 at 4:57 am

    Actually the docs say that if the mapping is not found “0L” is returned.
    http://developer.android.com/reference/android/os/Bundle.html#getLong(java.lang.String)

    (also the type “long” is a primitive and cannot be null).

    You could use this:
    http://developer.android.com/reference/android/os/Bundle.html#getLong(java.lang.String,%20long)

    in which you can define a default value to receive when the key is not found (e.g. -1).

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

Sidebar

Related Questions

The application I'm currently writing is using MVVM with the ViewModel-first pattern. I have
Application : I am working on one mid-large size application which will be used
Application uses Entity Framework 4.1 with database first approach. I have in database a
Application Settings.bundle contains a version number , which is automatically generated during build. From
Application I am working on an MMO and have run into an issue. The
Application frameworks such as DotNetNuke, Eclipse, Websphere and so forth are available today which
My application dynamically loads assemblies at runtime from specific subfolders. These assemblies are compiled
My application is not all to complicated. It retrieves a single entity from a
Application requests KML data through AJAX from server. This data is stored in javascript
Application.Run(form); Actually I tried to call this from my project. I got this exception.

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.