Passing Data through bundle using Intent - android-studio

I want to pass data from Activity1 to Activity2 and then Data of Activity1 and Activity2 combined in Activity3.
how am i supposed to do it Android Studio?

You can use intent extras to do this. Intent extras use a key/value pair system to store data. For example to put data you would say:
String name = "John Doe";
Intent intent = new Intent(this, Activity2.class);
intent.putExtra("myData", name);
startActivity(i);
Then in Activity2, you would retrieve the intent, and then get your data back:
Intent intent = getIntent();
String name = intent.getStringExtra("myData");
Now inside of this variable name, you will find "John Doe"

Related

(Kotlin)how can i get data from sharedpreferences in another activity

I have a settings activity and I want to use those settings on other screens I am developing an app to send balance for phones, normally the one who makes these sales must enter a series of codes on his sales phone, what I want is to save that annoyance to the vendor and have the codes fixed but there is a pin that is unique to each vendor which in my application should enter (your vendor pin) only once in settings and then not worry about anything
This is the settings Activity u have to enter your pin in that EditText and then the app have to remember the pin at each transaction u do
override fun onCreatelsavedInstanceState: Bundle?) {
super.onCreate(savedInstance5tate)
setContentView(R. Layout.activity_main)
loadData()
savebutton. setonClicklistener (){saveData() }
}
private fun loadData (){
val sharePref = getPreferences(Context.MODE_PRIVATE)
val mydata = sharePref.getString( key: "mydata", defValue: "")
dataEditText.setText (dato)
}
private fun saveData(){
sharePref = getPreferences (Context.MODE_PRIVATE)
with(sharePref.edit()){
putString("pin", dataEditText.text.tostring())
commit() ^with
}
}
You can use getSharedPreferences
Because getPreferences: use only one shared preference file for the activity.
getSharedPreferences: use this if you need multiple shared preference files identified by name, which you specify with the first parameter. You can call this from any Context in your app.
val sharedPref = getSharedPreferences(
getString(R.string.preference_file_key),
Context.MODE_PRIVATE
)

Add Files to Salesorder line item

I want to add files to salesorder line items in Acumatica using web services.
What endpoint should be used?
I want to add an image as shown in the screenshot above, using web service endpoint.
This is an old question, but I just came across this same issue while assisting a customer with a third-party integration. The third-party developers were adamant that they could only use the REST service, as they had already built the rest of their integration around it before realizing they couldn't attach files to sales order lines.
I was able to build a workaround using a customization. The issue at hand is that the way Acumatica's REST API attaches files is only accessible for Top-Level entities - which means there has to be a screen that uses the object as a primary DAC.
The workaround is to do just that, create a new custom screen that uses the SOLine object as it's primary DAC. In order to make the selectors available, I had to remove and replace a couple attributes on the key fields so that they could be visible and enabled. Here is the graph code - it's very simple, as this is basically just the bare minimum needed to be able to create a custom endpoint that uses the SOLine DAC as a top-level entity.
public class SOLineAttachmentEntry : PXGraph<SOLineAttachmentEntry, SOLine>
{
public PXSelect<SOLine> SOLineDetail;
[PXMergeAttributes(Method = MergeMethod.Append)]
[PXRemoveBaseAttribute(typeof(PXUIFieldAttribute))]
[PXUIField(DisplayName = "Order Type", Visible=true, Enabled = true)]
protected virtual void SOLine_OrderType_CacheAttached(PXCache sender) { }
[PXMergeAttributes(Method = MergeMethod.Append)]
[PXRemoveBaseAttribute(typeof(PXUIFieldAttribute))]
[PXUIField(DisplayName = "Order Nbr", Visible=true, Enabled = true)]
protected virtual void SOLine_OrderNbr_CacheAttached(PXCache sender) { }
[PXMergeAttributes(Method = MergeMethod.Append)]
[PXRemoveBaseAttribute(typeof(PXUIFieldAttribute))]
[PXRemoveBaseAttribute(typeof(PXLineNbrAttribute))]
[PXUIField(DisplayName = "Line Nbr", Visible=true, Enabled = true)]
protected virtual void SOLine_LineNbr_CacheAttached(PXCache sender) { }
}
The custom screen layout should be a simple Form with just these three key fields, OrderType, OrderNbr, LineNbr. In the Screen Editor of the customization, you'll want to set CommitChanges=true in the Layout Properties tab for each field.
Once the screen is published, you can use it to create a new custom endpoint and add a single entity by selecting the SOLine view from the custom screen. I named the endpoint "SalesOrderDetailAttach", assigned the endpoint version to be 1.0, and named the new entity "SalesOrderDetail". Using those names, the file attachment request should be a PUT request with the binary file data in the request body, using the url format:
[AcumaticaBaseUrl]/entity/SalesOrderDetailAttach/1.0/SalesOrderDetail/[OrderType]/[OrderNbr]/[LineNbr]/files/[Desired filename in Acumatica]
This worked for this one very specific case, attaching a file to the SOLine object. The screen and the endpoint should really never be used for anything else, and the custom screen should not be accessible to any users other than the administrator and the API user. Ultimately I would recommend using the Screen-Based method from the other answer, but if using the REST API is an absolute must-have, this is a potential workaround.
REST API needs to reference the detail line in the body. Since the body is used to pass the binary data of the attachment REST API can't be used to attach files to detail line.
Below is a screen based API snippet that creates a new master/detail document and attach images to the detail line. If you choose to use the screen based API you will need to adapt the snippet for sales order ASMX screen and fetch sales order with expanded details SOLine. The pattern to attach file will be the same:
string[] detailDescription = "Test";
List<string> filenames = "image.jpg";
List<byte[]> images = new byte[] { put_image_binary_data_here } ;
ServiceReference1.Screen context = new ServiceReference1.Screen();
context.CookieContainer = new System.Net.CookieContainer();
context.Url = "http://localhost/Demo/Soap/XYZ.asmx";
context.Login("admin#CompanyLoginName", "admin");
ServiceReference1.XY999999Content content = PX.Soap.Helper.GetSchema<ServiceReference1.XY999999Content>(context);
List<ServiceReference1.Command> cmds = new List<ServiceReference1.Command>
{
// Insert Master
new ServiceReference1.Value { Value="<NEW>", LinkedCommand = content.Document.KeyField},
new ServiceReference1.Value { Value="Description", LinkedCommand = content.Document.Description},
// Insert Detail
content.DataView.ServiceCommands.NewRow,
new ServiceReference1.Value { Value = noteDetail[0], LinkedCommand = content.DataView.Description },
// Attaching a file to detail
new ServiceReference1.Value
{
Value = Convert.ToBase64String(images[0]),
FieldName = filenames[0],
LinkedCommand = content.DataView.ServiceCommands.Attachment
},
content.Actions.Save,
content.Document.KeyField
};
var returnValue = context.PP301001Submit(cmds.ToArray());
context.Logout();

How to launch fragment from other app "package_name"

i want to open a fragment from an other "Application 1" and show it in "Application 2", i know if i want to call an activity i use this code :
Intent intent = new Intent();
intent.setComponent(new ComponentName("com.app1", "com.app1.MainActivity"));
startActivity(intent);
but now i want to use a fragment not activity!
How can i do it please ?
i tried to use
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new MainActivity()).commit();
but it didn't work.

Microsoft Bot Framework LUIS in waterfall conversation

I have an existing waterfall conversation. I want to adapt it so that it can extract data from more complex user responses to the bot's questions.
In my LUIS app I have created an intent called GetLocation which is trained to find an entity called Location. An example of this is the user typing "I am looking in Bristol" which would match the entity "Bristol". This is what I currently have:
function(session) {
builder.Prompts.text(session, "Hello... Which city are you looking in?");
},
function(session, results) {
session.privateConversationData.city = results.response;
builder.Prompts.number(session, "Ok, you are looking in " + results.response + ", How many bedrooms are you looking for?");
},
etc...
Instead of simply storing the response string, I want to send the response string off to LUIS and extract the city location from it. All of the LUIS examples I've found are for matching and going to new Intents however I simply want to keep the waterfall conversation going. How would I utilise LUIS to do this?
I think you can do this by having two different dialogs setup:
Dialog 1:
This is the dialog you have above, your normal Waterfall dialog that drives the conversation.
Dialog 2:
This dialog will be created with a LUIS Intent recognizer using your LUIS model. Dialog 1 will issue the prompt, then pass the user to this dialog and parse the text entered by the user. Since your Model is already trained to recognize location, all you need to do now is extract the entity.
After dialog 2 has parsed the location information using LUIS, and extracted the entity, you will end the dialog and return the entity (location) back to dialog 1, which will still be on the Dialog Stack.
Code
//create intent recognizer based on LUIS model
var luisModel = "<Your LUIS Model URL>";
var recognizer = new botbuilder.LuisRecognizer(luisModel);
//create dialog handler for info to be parsed by LUIS
var dialog = new botbuilder.IntentDialog({ recognizers: [recognizer] });
//root dialog
bot.dialog("/", [
function(session){
//prompt user and pop LUIS intent dialog onto dialog stack
session.send("Hello, which city are you looking in?");
session.beginDialog("/begin_loc_parse");
},
//this will be resumed after our location has been extracted
function(session, results){
//check for extracted location
if(results.entity){
//got location successfully
session.send("Got city from user: " + results.entity);
//resume normal waterfall with location.....
} else {
//start over
session.beginDialog("/");
}
}
]);
//LUIS intent dialog
dialog.matches("input_location", function(session, args){
//grab location entity
var city = botbuilder.EntityRecognizer.findEntity(args.entities, "builtin.geography.city");
if(city){
//pop the LUIS dialog off of the dialog stack
//and return the extracted location back to waterfall
session.endDialogWithResult(city);
} else session.endDialog("Couldn't extract city entity.");
});
//called if user doesn't enter something like "I am looking in [city]"
dialog.onDefault(function(session, args){
session.send("I'm sorry, I didn't quite catch that. In which city are you looking?");
});
So basically, in the root dialog, when you prompt the user for the location, and then call session.beginDialog("/begin_loc_parse") you will have passed the conversation to your LUIS intent dialog.
Any text entered by the user after this point will be interpreted by your LUIS model. This allows you to use your model to recognize and extract the location information from the user.
Then, the key is to use session.endDialogWithResult()to pop the LUIS dialog off the stack, and to go back to your original waterfall with your newly extracted location.

OnBackPressed() for different activities in same function

I want to navigate on previous activity by using onBackPressed(). I tried the following code :
Intent i=new Intent(detail.this,Data.class);
startActivity(i);
It's working, navigating on the Data.java file by manually. But my problem is that instead of Data.class there are other activities according to my need, like
Homepage.class==>Data.class====>detail.class
Homepage.class==>Inbox.class====>detail.class
Homepage.class==>Information.class====>detail.class
means like this,
For 1st condition
Intent i = new Intent(detail.this, Data.class);
startActivity(i);
For 2nd condition
Intent i = new Intent(detail.this, Inbox.class);
startActivity(i);
For 3rd condition
Intent i = new Intent(detail.this, Information.class);
startActivity(i);
Now my question is: how to know the previous activity class name and how to replace the class name data.class in following line automatically
Intent i = new Intent(detail.this, Data.class);

Resources