views:

105

answers:

0

I have an application that execute a specific task when a file is clicked or an HTTP links is shared to it. I only want to execute the task once, unless the user himself re-execute the task.

To be sure, I monitor the flag: FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY. If its set I ignore the task, if not, I execute it.

The problem is that sometime, the task gets execute 2 or 3 times anyway. Is there something else that I should be doing?

I'm doing the viewing of the state of the tasks, the adding by file clicking and the adding by link sharing all through one activity and checking the type of intent to take a different execution path and checking the previously mentioned flag to execute the task or not.

Here are some snippets of code: In the onCreate function:

Intent intent = getIntent();
String action = intent.getAction();
// Show the dialog only if the intent's action is not to view a
// content -> add a new file
if (action != null && (action.equals(Intent.ACTION_VIEW) || action.equals(Intent.ACTION_SEND))) {
    if ((intent.getFlags() & Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY) == 0){     
        handleIntent(intent);
    }
}

In the onNewIntent function:

super.onNewIntent(intentP);
if ((intentP.getFlags() & Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY) == 0){
    Log.d(Synodroid.DS_TAG, "New intent: " + intentP);
    handleIntent(intentP);      
}

I'm not checking the flag anywhere else. Am I missing an entry point? Am I doing something wrong? Is that flag really reliable?

Thx, Steve