0

Is it possible to change the value of the android:noHistory attribute of an Activity programmaticaly and on the fly?

Or maybe there is another way to do what I want. I have an activity with QuickContactBadges on it... I want it to close the activity when after popping up a QuickContact, which is why I have noHistory on, but the activity also launches a configuration activity. I do NOT want it to close when coming back from that activity (rather it should refresh, which I can do if I can stop it from closing).

eidylon
  • 7,068
  • 20
  • 75
  • 118
  • I had the same necessity and after hours looking for a solution, this question was the only one that helped: https://stackoverflow.com/a/28198765/2205502 – Guybrush Aug 02 '18 at 14:47

2 Answers2

2

Revised Answer

You can start with a default boolean value of true to be used as a trigger in the onPause() method of your Activity to tell you whether or not you want to call finish(). If the user reaches the portion of your Activity that calls your Configuration Activity, set the boolean to false so the Activity will not be finished nor removed from the stack.

Glendon Trullinger
  • 4,052
  • 1
  • 28
  • 35
  • The QuickContactBadge though is a self-contained widget, no? Can I hook into it like that? I'd originally tried attaching an event handler to the QuickContactBadge `onClick` event, but it override the inherent click event and the badge would no longer show the QuickContactCard when the user clicked on it. (I had thought the noHistory flag fixed this, until I got to this point.) I don't see an `onStartActivity` event on the QuickContactBadge. – eidylon Jun 11 '11 at 05:22
  • Ah, sorry, I didn't realize the objects you named in your question were part of the API. I actually implemented a very similar widget on my own. Anyway, how about using a boolean value as a trigger? You can have it set to a default value of "true." If the user hits your Configuration Activity, set it to false. Otherwise, in the `onPause()` of your original Activity, if the boolean is true, call `finish()`. – Glendon Trullinger Jun 11 '11 at 06:10
  • Ooh, that sounds like it might work; I will have to give that a try and report back... – eidylon Jun 11 '11 at 06:13
  • 1
    This worked like a beauty! Though, I wanted my first activity to be visible behind the QuickContactBadge, so I actually used the `onResume()` event instead of the `onPause()` event. Thanks a lot! – eidylon Jun 13 '11 at 04:00
-2
<activity android:allowTaskReparenting=["true" | "false"]
          android:alwaysRetainTaskState=["true" | "false"]
          android:clearTaskOnLaunch=["true" | "false"]
          android:configChanges=["mcc", "mnc", "locale",
                                 "touchscreen", "keyboard", "keyboardHidden",
                                 "navigation", "orientation", "screenLayout",
                                 "fontScale", "uiMode"]
          android:enabled=["true" | "false"]
          android:excludeFromRecents=["true" | "false"]
          android:exported=["true" | "false"]
          android:finishOnTaskLaunch=["true" | "false"]
          android:hardwareAccelerated=["true" | "false"]
          android:icon="drawable resource"
          android:label="string resource"
          android:launchMode=["multiple" | "singleTop" |
                              "singleTask" | "singleInstance"]
          android:multiprocess=["true" | "false"]
          android:name="string"
          android:noHistory=["true" | "false"]  
          android:permission="string"
          android:process="string"
          android:screenOrientation=["unspecified" | "user" | "behind" |
                                     "landscape" | "portrait" |
                                     "sensor" | "nosensor"]
          android:stateNotNeeded=["true" | "false"]
          android:taskAffinity="string"
          android:theme="resource or theme"
          android:windowSoftInputMode=["stateUnspecified",
                                       "stateUnchanged", "stateHidden",
                                       "stateAlwaysHidden", "stateVisible",
                                       "stateAlwaysVisible", "adjustUnspecified",
                                       "adjustResize", "adjustPan"] >   
    . . .
</activity>

try this link->http://developer.android.com/guide/topics/manifest/activity-element.html