Multiple activities: intent and sharedpreferences don't work between all activities - android-activity

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.

Related

Close session of choice in unified service desk

We have multiple sessions i-e four sessions opened in USD. I need to close without clicking on 'X' on the session.
Can it be possible to have 4 buttons on the toolbar and by clicking the third button will close the third session in USD?
This should be possible provided that Microsoft's documentation is valid. Even if it is possible, it would be crude, limited, and difficult to implement/maintain without writing custom code. I highly recommend a "close current session" button that simply closes the foreground session. Through configuration however, here's how you could theoretically do what you're asking.
Create a Close button for each session, considering your max number of sessions, let's say 4. On start of a new session, a series of actions fires in an attempt to locate a Close button upon which to attach the session close command, based on logic like this:
Does Global Context variable Session1ID have data?
If not, place the new session ID in Session1ID.
Does Global Context variable Session2ID have data?
Is the new session ID already stored in Session1ID?
If not, place the new session ID in Session2ID.
Does Global Context variable Session3ID have data?
Is the new session ID already stored in Session1ID or Session2ID?
If not, place the new session ID in Session3ID.
Does Global Context variable Session4ID have data?
Is the new session ID already stored in Session1ID, Session2ID, or Session3ID?
If not, place the new session ID in Session4ID.
The buttons themselves could be made visible or enabled based on whether their Session ID is in Global Context.
On click of any of these buttons, let's say #3, the following would occur:
Close Session command using Session3ID
Nullify value of Session3ID, making it available for the next attempt to attach a session ID.
I foresee a few problems with this. You may encounter issues reading from and writing to Global Context variables while inside of a session. Furthermore, you may encounter issues with closing background sessions by their ID.
Further still, closing sessions out-of-sequence would cause new sessions to attach to buttons in a disorderly-looking fashion, creating a bad user experience. Let's say you need to start six sessions (A, B, C, D, E, and F). You have to close the two sessions in the middle (B and C) before starting the last two due to your limit of 4. With A on button 1 and D on button 4, you start sessions E and F which attach to buttons 2 and 3. Now your four buttons correspond to sessions A, E, F, and D, while the session tabs themselves are in the order that you opened them: A, D, E, F. This would be a bad user experience. (I don't believe that you can manipulate the order in which buttons appear using replacement parameters. Button Order is likely to be configuration integers only.)
Hopefully, this clarifies the elegance of a simpler solution: Create a "Close Current Session" button that is only enabled or visible while you have a session.

jBPM 6 - How to hold Task from Rest API

How can I suspend a Task from Rest API.
I'm using the following code
RuntimeEngine engine = sessionBean.getEngine(implementationId);
TaskService taskService = engine.getTaskService();
taskService.start(taskId, actorId);
taskService.complete(taskId, actorId, data);
It works fine, now I want to save task Status between start and complete in different moments, but I don't know How to pass the data Map in order to hold the actual State.
taskService.suspend(taskId, actorId);
You can take a look at the implementation of the Save operation in the jbpm console.
That's done via saving the output values of the task as far as remember. By the way, suspend is not the right method to call to save the state, because it means a completely different thing.
You can start looking at here: https://github.com/droolsjbpm/jbpm-console-ng/blob/master/jbpm-console-ng-human-tasks-forms/jbpm-console-ng-human-tasks-forms-client/src/main/java/org/jbpm/console/ng/ht/forms/client/editors/taskform/FormDisplayPresenter.java
and go down to the actual implementation.
Regards

Android: Keep multiple instances of an activity in the back stack

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.

How to start an activity from other activity but with specific intent - from OnNewIntent

Ok... so i guess the title is a bit confusing. so i will explain:
I have an NFC app which i handle a NDEF_DISCOVERED succesfuly in activity A. then a new activity is launched (B).
In this new activity (B) i want to be able to catch another tag and let activity A handle it as before, so i use OnNewIntent to get this intent of the tag and want to start activity A.
But if i call startActivity(myIntent) with the traditional myIntent = new Intent(this, A.class) then activity A launced with this myIntent and i want the activity A to handle the tag intent that was 'caught' on activity B..
how can i do that?
Thanks.
You should be able to add your tag intent in activity B as an extra to the traditional intent with myintent.addExtra("tagkey", tagIntent). Because Intent implements Parcelable, it will be added as a Parcelable extra. Then in the onCreate() of activity A, put something like:
Intent intent = getIntent();
if (intent.hasExtra("tagkey")) {
setIntent(intent.getParcelableExtra("tagkey")
}
Replace the string "tagkey" with whatever is most relevant to your own code. You can put a similar snippet in onNewIntent() as well.
If the NDEF message type is specific enough such that only your Activity A will match it, you can set 'android:launchMode="singleTask"' in the activity section of your Android manifest for this Activity. Activity B will then be closed whenever you scan a new tag with the same type of NDEF message.

Saving and reading int values in case of app close

I've created an application which contains settings as int values... Basically my app contains multiple layouts. When the user presses the "back" key, the app returns to the first panel (which is the main screen!). If pressed on the main screen, the app will pause/finish.
The integer values that I have are what I use to determine whether the user has done something in the app. They also determine which layout the user is in.
I really need to have these int values for when the user opens the app again. What is the best way that I should go about saving multiple int values so that I can access them if the app is killed?
Thanks
Sorry... I'm finding it really hard to write and read to and from a map file... Here is what I have so far simplified. Can you see if I am missing something... more than likely its really easy.
Sub Activity_Resume
Dim m As Map
m.Initialize
If File.Exists(File.DirInternal, "1.txt") Then
m = File.ReadMap(File.DirInternal,"1.txt")
int1 = m.Get("int1")
int2 = m.Get("int2")
End If
End Sub
Sub Activity_Pause (UserClosed) As Boolean
Dim m As Map
m.Initialize
m.Put("int1", int1)
m.Put("int2", int2)
File.WriteMap(File.DirInternal, "1.txt", m)
End Sub
You have several options. You can use StateManager or you can store the settings in a Map and then in Activity_Pause save the Map with File.WriteMap, and read the Map in Activity_Create if the file exists.