I have an Activity A from which I start Activity B. In Activity B I want to start a new instances of B (with different contents), so that I can navigate back to different instances of B. For example:
A -> B (with content x) -> B' (with content y) -back-> B (with content x)
My problem:
For an example navigation path:
A -> B -> B' -> B''
when pressing back in B'' I return to A and not to B' as expected.
Doesn't android store instances of an activity in the back stack or do I have to do something to tell android to save every single instance so I can navigate between them?
You should read Google's Tasks and Back Stack document.
Related
I am using a GraphMachine to model a workflow of a MongoDB record.
I am only storing the state in MongoDB and when I am reloading at a later time, I use the set_state() option on the machine to force it back to where it was left off.
This all works correctly except when I try to show the state machine graph.
After loading it always shows itself in the initial state even though it seems it did accept the set_state because transitions are accepted as if it was in the restored state.
Lets say I have a simple linear FSM like: S0 -> S1 -> S2 -> S3 -> S3 -> S0.
S0 is the initial state, and S2 is where it was saved.
When I restore, it always graphs itself in S0, but if I try to make the S2->S3 transition, it accepts it. When I make the graph afterwards, it is in the correct S3 state.
Is there a way I can make the GraphMachine 'initialize' to the correct state?
Thanks
Machine.set_state will hard set the model state but won't call necessary callbacks to regenerate the graph. You can either pass the initial state to the constructor or force a recreation of the graph after set_state:
from transitions.extensions import GraphMachine
states = ["A", "B", "C"]
m1 = GraphMachine(states=states, initial="A", ordered_transitions=True, show_state_attributes=True)
m1.next_state()
m2 = GraphMachine(states=states, initial=m1.state, ordered_transitions=True)
m2.get_graph().draw("machine2.png")
m1.set_state("C")
m1.get_graph(force_new=True).draw("machine1.png")
I'm working on a project where i have a window with a size of 4 days, with a step of 1 day
.timewindow(Time.days(4), Time.days(1))
and i have also a trigger
.trigger(new myTrigger)
onEventTime ---> Continue
onProccessingTime ---> Continue
clear ---> Purge
onElement---> (if element.isFinalTransaction) TriggerResult.FIRE_AND_PRUGE
isFinalTransaction is a boolean, when true it call FAP.
the mean question is how can i make it return true/false depending on if the element is the last in the window or not
is there any method that can tell us if the current element is the last one in the window?
is there any method that can tell us if the current window is done (before sliding) or not ?
From the abstract trigger class (https://github.com/apache/flink/blob/master//flink-streaming-java/src/main/java/org/apache/flink/streaming/api/windowing/triggers/Trigger.java)
The short answer is no. The method onElement is called for every element that gets added to the pane. When an element gets added it's impossible to know if it is the last element, because that information is not known until the next element comes (and we see if it was in this window or the next one).
However, one alternative would be to check if the element is sufficiently close to the end of the end of the window (because onElement has access to window e.g. if (timestamp > window.getEnd - delta) ...
However, I can not think of a use case in which I would recommend this. If you need access to the last element in the window, you should probably just use a WindowFunction and in the apply method get the last element of the input iterable (input.last).
I have an application with 3 activities let's call them A,B and C.
To switch between them, i use startactivity and it's working fine but when i want to pass data using putExtra or sharedpreferences : from A to B, there is no problem but from B to C the application crash.
Activity A
Intent B = new Intent(getApplicationContext(),activityB.class);
B.putExtra("adresse-ip", "192.168.1.9");
startActivity(B);
Activity B
Intent C = new Intent(getApplicationContext(),activityC.class);
C.putExtra("adresse-ip2", "abc"); //When i add this line the apllication crash
startActivity(C);
Even when i used sharedpreferences, i got the same problem when i read the data in activity B it works fine but when i do the same in activity C the application crash.
It seems that there is a problem with activity C. Make sure that Activity C is defined in AndroidManifest just like A and B; and also make sure that C is properly defined as an activity.
I'm trying to play with Om (yes, I know om.next is coming, but it's not clear when it will be ready--and I think the basic idea will apply), but have run into a simple (or should be) problem.
I have a component with a select widget that populates from the "effects" member of my app-state, and a button to send that effect downstream (controlling LED strips):
(defn effect-view [data owner]
(reify
om/IInitState
(init-state [_]
{:selected-effect nil})
om/IRenderState
(render-state [this state]
(dom/div {}
(dom/select #js {:id "effect"
:value (:selected-effect state)
:onChange #(handle-change % owner state)}
(for [effect (:effects data)]
(dom/option {:react-key (:name effect)} (:name effect))))
(dom/button #js {:id "send-effect"
:onClick (fn [e]
(queue-command "effect" (:selected-effect state)))
:react-key "send-effect"}
(str "Send Effect"))))))
Good so far actually; this mostly works. When the app-state is populated with :effects (via a REST call), this does indeed fill in the options.
The problem is that pesky :selected-effect state member. It's initially nil, but once the select element is populated, the selector displays the first element. So if the user clicks the "Send Effect" button, rather than getting the first effect it sends "nil"--because the "option" children are being filled in correctly but the view state hasn't changed.
When I change the effect list in the global state, I'd like the value of the selector (:selected-effect) in the view to change to the first item in the list, if the current value isn't valid (in other words, it starts at nil and I populate with effects A, B, and C--it should change the selected value to "A"... if I then populate with effects A, C, and D, it should stay A, but if I populated with B, C, D, it should then switch to B, if that makes sense.
How do I do this?
Solved! By... reading the documentation closer. Sigh.
The IWillReceiveProps protocol is called before the next props (app state) is actually set. So the following sets the component state prior to rendering. With this code added before om/IRenderState the code seems to do what I desired:
om/IWillReceiveProps
(will-receive-props [this next-props]
(let [effect-names (map :name (:effects next-props))]
(if-not (contains? effect-names (om/get-state owner :selected-effect))
(om/set-state! owner :selected-effect (first effect-names)))))
God deal; I consider this closed and can get on with the project.
I have a file browser type application consisting of a CellTree displaying the hierarchy and a browser pane showing the contents of the current node.
The application has to handle hierarchies which may be too large for the CellTree to handle effectively, so the location shown in the browser pane is not strongly coupled to the open nodes in the tree.
I wish to implement a button which will open the current browse location in the CellTree. My server side data model has parent/child references on all objects so obtaining the hierarchy is a simple matter, but I am struggling with how to apply this to the tree.
This is my current attempt, it is a method on the widget which contains my tree, and is called from the reciever. The RecordTreeLevel objects each represent a level in the tree.
public void navigateTo(List<RecordTreeLevelProxy> hierarchy) {
TreeNode currentNode = tree.getRootTreeNode();
ListIterator iter = hierarchy.listIterator(hierarchy.size());
while (iter.hasPrevious()){
RecordTreeLevelProxy level = (RecordTreeLevelProxy) iter.previous();
Integer nodeIndex = locateNode(level.getUniqueRef(), currentNode);
if (nodeIndex != null){
currentNode = currentNode.setChildOpen(nodeIndex, true, true);
}
}
}
This doesn't work, because the loop completes in its entirity before the children are added to any of the nodes. Therefore the first level node opens as it should, but doesn't have any children when the loop comes around the second time.
I can't help but feel that I'm missing something obvious, or doing this in the wrong way, but I can't see it. Any help much apprieciated (even if it's to say "don't be silly, you can't do it that way)
Your code should work if you populate the data synchronously from your TreeViewModel (provided locateNode does what I think it does, i.e. iterate over currentNode.getChildValue(i) with i between 0 and currentNode.getChildCount()).
What I'm doing in a similar scenario (I'm actually doing it with a CellBrowser) is that I preload the cache (I'm caching the response for the various branches of the tree) using the hierarchy to the selected node, and then run code very similar to yours. The TreeViewModel runs synchronously if the value is in the cache, asynchronously otherwise (asking the server for the children of the opened node).
For example, for the following tree:
- A
+- A1
+- A1a
+- A2
+- A2a
+- A2b
- B
+- B1
+- B2
If the A2a node should be pre-selected, I start by load the root branch, the A branch, then the A2 branch:
<root> -> [ A, B ]
A -> [ A1, A2 ]
A2 -> [ A2a, A2b ]
That way, I'm sure my TreeViewModel will run synchronously for the nodes <root>, A and A2.
And then only I run the setChildOpen code. Because the TreeViewModel is synchronous for these nodes, setChildOpen returns a non-null value.