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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:06:23+00:00 2026-05-28T02:06:23+00:00

I`m working on an app that does reading and handling specific URIs from NFC

  • 0

I`m working on an app that does reading and handling specific URIs from NFC tags. I have a “reader” activity (A) registered on NDEF_DISCOVERED which reads the data from the tag and than launches a “data handling” activity (B) that operates with the data.

Currently I have three tags, each with a different URI, more specifically with the same schema and path, but with different query data –> the tagID:

T-1: mySchema://gman.com/path?id=T-1
T-2: mySchema://gman.com/path?id=T-2
T-3: mySchema://gman.com/path?id=T-3

Manifest:

   <activity
        android:label="@string/reader_nfc"
        android:name=".reader.nfc.NfcReaderActivity"
        android:stateNotNeeded="true" >
        <intent-filter>
            <action android:name="android.nfc.action.NDEF_DISCOVERED" />
            <category android:name="android.intent.category.DEFAULT" />
            <data android:scheme="mySchema" />
        </intent-filter>
    </activity>
    <activity
        android:label="@string/data_manager_name"
        android:name=".data.handlers.DataHandlerActivity" >
    </activity>

So, getting to the problem. When I read the data from the first tag, for example T-1, the reader activity goes normally trough the lifecycle and launches the data handling activity which does its job and shows the correct output. The same thing happens when I read from the next tag (T-2 or T-3), but when I return to the first tag I get the output produced from the last-previously scanned tag.

The log shows something like this:

the ActivityManager logs the the start of the intent with the right data (from T-1) but the lifecycle of activity A doesn`t get started, instead activity B restarts and the data from the previous intent is received and handled (by calling getIntent().getData() in activity B).

When switching between T-2 and T-3 everything works fine.

I would really appreciate if someone explaind me what is going on. I saw similar behaviour when setting singleTask launch mode, but I`m not using it.

I`m developing on API v.2.3.3, testing on Nexus-S with android version 2.3.6

Thnx!

==================================================================================

EDIT: I found a solution on my problem which fits my needs, still I have a question.

I focused on the reader activity and commented out the handling and the other stuff that was going on. Here is the code snipet:

public class NfcReaderActivity extends Activity {

private static final String TAG = "NfcReaderActivity";

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Log.d(TAG, "onCreate");
    setContentView(R.layout.nfc_reader);
}

@Override
protected void onStart() {
    super.onStart();
    Log.d(TAG, "onStart");

    readAndHandleData();
}

protected void readAndHandleData() {
    NdefMessage[] srcObj = readSource();

    if (srcObj != null) {
        Uri srcData = getSrcData(srcObj);
        launchSourceManagerActivity(srcData);
    } else {
        Log.w(TAG, "srcObj was null!");
    }
}

public NdefMessage[] readSource() {

    Parcelable[] rawMsgs = getIntent().getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES);
    NdefMessage[] ndefMsgs = null;
    // store NdefMessage-s from rawMsgs in ndefMsgs
    return ndefMsgs ;
}

public void launchSourceManagerActivity(Uri srcData) {
    // launches DataHandlerActivity with srcData
}

public Uri getSrcData(NdefMessage[] src) {
    // returns the data from the tag rapresented as Uri
}

}

After doing this I got some extra logs (don’t know why, but I guess this is not that important), and saw that when I’m returning to the first tag, the activity gets restarted (onRestart() is called), whereas in the other two cases, when scanning the second and the third tag, the activity is recreated (onCreate() is called).

When onRestart() is called and I retrieve the data from the intent (readSource method), the getIntent() method returns the same intent received when scanning the previous tag.

I just recently started developing on Android and I`m not very familiar with the concepts, so maybe this is the core problem here ;). I tried to figure this out but I just can’t get to a logical explanation. If someone could explain me the workflow here I would be really grateful.

However, this is how I resolved the issue…since the reader activity can act as a singleton I’ve set the launch mode as singleTask

<activity
        android:label="@string/reader_nfc"
        android:name=".reader.nfc.NfcReaderActivity"
        android:stateNotNeeded="true"
        android:launchMode="singleTask"  >

and done the following changes in NfcReaderActivity:

public class NfcReaderActivity extends Activity {

private static final String TAG = "NfcReaderActivity";

/**
 * override onNewIntent method and store the new intent as the current intent
 */
@Override
protected void onNewIntent(Intent intent) {
    super.onNewIntent(intent);
    Log.d(TAG, "onNewIntent");
    // set the intent as the current intent, so new data (EXTRA_NDEF_MESSAGES) can
 //be accessed when calling getIntent() in readSource method
    setIntent(intent);
}

This works fine for me, but I would still like to understand what exactly was happening, so any useful (of course 😉 ) comments are welcome.

  • 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-28T02:06:24+00:00Added an answer on May 28, 2026 at 2:06 am

    You might want to read up on the activity lifecycle and stack:

    http://developer.android.com/guide/topics/fundamentals/tasks-and-back-stack.html

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

Sidebar

Related Questions

I have a nice little app on the app store that does pretty well
I am working on an app that will play back notes from a 12-tone
I'm working on an app that's using System.Net.Mail.MailAddress and friends for sending emails. Does
Id have an app that does one thing if you shake it one way,
I have a nice little app on the app store that does pretty well
I'm working on a javascript app that does a lot of Date arithmetic, and
I have an App that does the pretty standard operation: It plays audio (streamed
I have an app that posts a string to user's wall. The app worked
So, in an iPhone app I am working on, I've decided that the best
I am working on an app that monitors network usage. However I noticed many

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.