OnBackPressed() for different activities in same function - onbackpressed

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);

Related

How to solve "Changes cannot be saved to the database from the event handler"?

In POOrderEntry as a POLine is created or deleted, I need to push a reference back to a custom DAC that originates the PO Line. For instance, if the PO Line is deleted, my custom DAC has the reference removed in Events.RowDeleted via:
using (PXTransactionScope ts = new PXTransactionScope())
{
Base.Caches[typeof(MyDAC)].SetValueExt<MyDAC.pOType>(row, null);
Base.Caches[typeof(MyDAC)].SetValueExt<MyDAC.pONbr>(row, null);
Base.Caches[typeof(MyDAC)].SetValueExt<MyDAC.pOLineNbr>(row, null);
Base.Caches[typeof(MyDAC)].Update(row);
Base.Caches[typeof(MyDAC)].Persist(PXDBOperation.Update);
ts.Complete(Base);
}
I have tried to allow the normal Persist to save the values, but it doesn't unless I call Persist (last line of my example above). The result is an error via Acuminator of "Changes cannot be saved to the database from the event handler". As I look at this, I wonder if it should be in an Long Operation instead of a Transaction Scope, but the error from Acuminator tells me I'm doing this wrong. What is the proper way to achieve my update back to "MyDAC" for each PO Line?
I have also tried initializing a graph instance for MyDAC's graph, but I get a warning about creating a PXGraph in an event handler so I can't "legally" call the graph where MyDAC is maintained.
My code compiles and functions as desired, but the error from Acuminator tells me there must be a more proper way to accomplish this.
You can add a view to the graph extension.
Then in the row deleted you will use your view.Update(row) to update your custom dac.
During the base graph persist your records will commit as long as there are no other errors found in other events.
The way you have it now commits your changes with a chance the row that was being deleted is never deleted.
Also with this change there is no need to use PXTransactionScope.
An example might look something like this...
public class POOrderEntryExtension : PXGraphExtension<POOrderEntry>
{
public PXSelect<MyDac> MyView;
protected virtual void _(Events.RowDeleted<POLine> e)
{
//get your row to update from e.Row
var myRow = PXSelect...
myRow.pOType = null;
myRow.pONbr = null;
myRow.pOLineNbr = null;
MyView.Update(myRow);
}
}

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.

Passing Data through bundle using Intent

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"

Error #153 Another process has added 'Note' record. Your changes will be lost(SalesOrderEntry)

In the Sales Order page, I created a custom button which purpose is to save and refresh the page. Currently it saves fine and processes the new order to an order number but when I try to add an item/edit or perform an action in the drop down menu I receive the error message.
Here's my code:
public PXAction<SOOrder> SRefresh;
[PXUIField(DisplayName = "S RefreshT")]
[PXButton(CommitChanges = true)]
protected virtual IEnumerable sRefresh(PXAdapter adapter)
{
SOOrderEntry graph = PXGraph.CreateInstance<SOOrderEntry>();
Base.Actions.PressSave();
SOLine sLine = PXSelect<SOLine, Where<SOLine.orderNbr, Equal<Required<SOLine.orderNbr>>>>.Select(graph, this.Base.Document.Current.OrderNbr);
if (sLine != null && sLine.InventoryID.HasValue)
{
graph.Document.Current = graph.Document.Search<SOLine.orderNbr>(sLine.OrderNbr);
throw new PXRedirectRequiredException(graph, null);
}
return adapter.Get();
}
I've also tried using graph.Persist() as said in the manual instead of Action.PressSave(); with no success.
I appreciate any input you guys may have, Thank you
Since you're working with the current sales order, you don't need to create a new instance of the sales order entery graph and redirect your user. You can work with the Base object and run all your logic on it.
Base.Document.Current contains a reference to the current SOOrder, and Base.Transactions contains the list of SOLine of this document. Another problem I also found in your code is that you're calling Document.Search<SOline.orderNbr>; it should be SOOrder.orerNbr since you're searching inside the Document view, which contains sales orders, and not lines. In this case, it's not even necessary to search, Base.Document.Current will already be set to the order you're looking at.
I strongly recommend completing the standard Acumatica developer trainings - T100, T200, T300; this stuff is all covered and will get you productive quickly

Retrieve Current ID Crm Online

Entity title = new Entity();
title = service.Retrieve("incident",((Guid)((Entity)context.InputParameters["Target"]).Id), new ColumnSet("title"));
I am using this code to get the current id of an Incident while i'am closing it!
But received this error :
Unexpected exception from plug-in (Execute): FecharIncidente.Plugins.PostIncidenteClose: System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.
One of my mates uses exactly the same code and is working on his crm !
Some help !?!
Apparently your InputParameters collection doesn't have a "Target" key value. Check that the request that you're using has a "Target" InputParameter.
if (context.InputParameters.Contains("Target") &&
context.InputParameters["Target"] is Entity)
{
// Obtain the target entity from the input parameters.
title = service.Retrieve("incident", ((Entity)context.InputParameters["Target"]).Id, new ColumnSet("title"));
Bet you "Target" in not Contained in InputParameters, resulting in KeyNotFoundException - "The given key was not present in the dictionary."
your can check for Target like Daryl explained or use the context available from the workflow rather like so ...
protected override void Execute(CodeActivityContext executionContext)
{
// Create the context
var context = executionContext.GetExtension<IWorkflowContext>();
var title = new Entity();
//context.PrimaryEntityName - should hold string incident
//context.PrimaryEntityId - should hold your guid
title = service.Retrieve(context.PrimaryEntityName, context.PrimaryEntityId, new ColumnSet("title"));
}

Resources