Global Variables to specify a starting Activity - global-variables

I need to create some global android variables. Some posts here suggested me to do something like this:
public class MyAppName extends Application {
String foo;
//then, to create setters and getters...
}
and, to add android:name=".MyAppName" to manifest.
But now I am struggling with some basics that I missed along the way while trying to learn android.
My starting activity was named MyAppName. Now, of course I had to rename it, for example: MyStartingActivity.
The question is how do I start my MyStartingActivity. Where do I specify this activity as starting activity? Can I set some other activity to be the starting one?
I tried to StartActivity in OnCreate method of my application, but my app would force close every time.

Your Android Manifest is where you define the activities used by your application, and where you define which ons is your Main activity.
In order to define an activity as being your main, you need to make the intent filter of your activity look like this, in the manifest file:
<activity android:name="your.activity.name"
... >
<intent-filter ... >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

Related

How to override function from core service

The plan is to remove some fields from the default Shopware 6 registration form.
I've copied some twig-templates to my plugin and removed the fields like billingaddress etc ...
An error occurred in the validateRegistrationData function because the field value for billingaddress is null (sounds logic because I've deleted the field in the twig-template)
in vendor/shopware/platform/src/Core/Checkout/Customer/SalesChannel/RegisterRoute.php (line 259)
In my module I would like to override below function in the RegisterRoute.php file (service)
private function validateRegistrationData(...) { ... }
What steps are needed to properly override above function from within my custom shopware 6 plugin.
IMHO validateRegistrationData is only the first place where you have an issue, even you change the validation billing address variable is required below in \Shopware\Core\Checkout\Customer\SalesChannel\RegisterRoute::register() method.
Some my suggestion to you is implementing your own RegisterRoute in your plugin and decorate or even override existing core service.
So steps:
implement own RegisterRoute in your plugin
Register it in service container with the same id as core route:
<service id="Shopware\Core\Checkout\Customer\SalesChannel\RegisterRoute"
class="YourPlugin\Core\Checkout\Customer\SalesChannel\RegisterRoute" public="true">
<!-- your own arguments -->
</service>
Also I think you need to implement your own CustomerValidationFactory and AddressValidationFactory if it is needed by your business logic.
Anyway, you can also face the issue that some fields are required by Customer DAL definition, but you don't set them. So most probably you also need to change a bit CustomerDefinition, i mean override of course.

What is equivalent of RegisterInstance<Interface>(new Class()) design time?

I am trying to implement design time Unity configuration (e.g.: using app.config). I am struggling with the very example of how to use the tag the "configuring instances" section.
Their sample of run-time configuration is:
EmailService myEmailService = new EmailService();
myContainer.RegisterInstance<IMyService>(myEmailService);
but no equivalent design-time configuration given. If I do:
<container>
<instance type="IMyService" value="EmailService" />
</container>
I will naturally get a "TypeConverter cannot convert from System.String" exception. Am I supposed to create some sort of type converter merely so that I could declare an instance? Is there an easier way?

Getting org.testng.TestNGException: No free nodes found in:[DynamicGraph Exception

I want to write same class more than once in my testng.xml.
for e.g i have two methods login() and logout() in Login class.
First i want to execute Login class's login() method then OtherClass's method() and finally Login class's logout() method
<test name="scenario1">
<classes>
<class name="com.webaut.Login">
<methods>
<include name="login" />
</methods>
</class>
<class name="com.webaut.OtherClass">
<methods>
<include name="method" />
</methods>
</class>
<class name="com.webaut.Login">
<methods>
<include name="logout" />
</methods>
</class>
</classes>
</test>
After executing my suit i get an "org.testng.TestNGException: No free nodes found in:[DynamicGraph Exception"
I could have used #DataProvider, but my methods are different so please suggest any alternative.
It appears that each class can only be declared once in the list, even if different methods are included on each declaration, otherwise you will see this error message :( Using latest TestNG 6.8.8. I was able to get this to work with #Test(priority=#) with the specific priority on each test method. See http://testng.org/doc/documentation-main.html#annotations.
My use case: crud tests for entities. Each Entity has its own test class with 4 methods (so I can test only a single entity CRUD in isolation), but I also want to run the overall suite (will fail due to integrity constraints and different generated ID keys unless they are run in exactly the right order).
Same question asked at org.testng.TestNGException: No free nodes found in:[DynamicGraph.

How to override a Plone event subscriber

I need to extend a Plone product (Products.Poi) with a second product.
In the extension product i need to override a subscriber event of the original.
I tried to subscribe in an override.zcml an event with the same name but the second event don't override the first but all two are execute.
Here http://plone.org/products/dexterity/documentation/manual/five.grok/core-components/events seem that is not possible:
Unlike adapters, you cannot override an event subscriber by using a more specific interface. Each and every applicable event subscriber will be executed when an event is fired.
Someone has a trick?
Thanks Alex
Simone Orsi gave me a solution: z3c.unconfigure.
This product permit to disable zcml configuration.
To use it, I executed this step on my extented Poi product:
Added "z3c.unconfigure" as install_requires in the setup.py
Create event.py with the new definition of update_tracker_watchers
In the overrides.zcml add this line to unconfigure Products.Poi.events.update_tracker_watchers and to register my new event
<include package="z3c.unconfigure" file="meta.zcml" />
<unconfigure>
<subscriber
for="Products.Poi.interfaces.ITracker
Products.Archetypes.interfaces.IObjectEditedEvent"
handler="Products.Poi.events.update_tracker_watchers"
/>
</unconfigure>
<subscriber
for="Products.Poi.interfaces.ITracker
Products.Archetypes.interfaces.IObjectEditedEvent"
handler=".events.update_tracker_watchers"
/>
When you specified the overrides.zcml, you also need to register the zcml override in buildout? Take a look at: http://developer.plone.org/components/zcml.html?highlight=zcml#overrides It'd be something like: zcml = my.package-overrides
Additionally, you can try using the z3c.unconfigure package: http://pypi.python.org/pypi/z3c.unconfigure

Specify run time parameter dependency in Unity

I have a class which needs a string as a parameter in its constructor but this parameter will be decided by the calling code. At the same point of time, the life time of this class has to be tied to per HTTP request. So, I created a custom PerWebRequestTimelineManager and used that for my target type in the config file. But since the string in the constructor has to be dynamically determined, I cannot use the ConstructorInjection via the config file. I can use an abstract factory to solve the problem of dynamic dependency, but I am not sure about the implementation: Can you check the code below and validate the approach. Specifically the RegisterType and Resolve calls seem a bit out of place though the successive Resolve calls across the application will be able to retrieve the same instance.:
public class PerformanceTracerFactory : IPerformanceTracerFactory
{
private readonly IPerformanceTracer tracer;
public IPerformanceTracer CreateInstance(string operationTitle)
{
_container.RegisterType<IPerformanceTracer, PerformanceTracer>(new InjectionConstructor(operationTitle));
return _container.Resolve<IPerformanceTracer>();
}
}
Relevant portion of config file:
<register type="IPerformanceTracer" mapTo="PerformanceTracer">
<lifetime type="PerWebRequest"/>
</register>
<register type="IPerformanceTracerFactory" mapTo="PerformanceTracerFactory"/>
I have another question. In case if the above way of configuring and injecting the dependency using code is correct, then I think I do not need the config entries. I can always use the suitable overload to push the custom lifetime manager. In case, I would want to achieve the same thing using only config file, then how do I code the solution?
If you use a container-based factory you don't have to register/resolve your IPerformanceTracer in each call.
Register the mapping IPerformanceTracer --> PerformanceTracer once in your config file and use a ParameterOverride when you resolve your interface.
public IPerformanceTracer CreateInstance(string operationTitle)
{
return _container.Resolve<IPerformanceTracer>(new ParameterOverride("nameOfTheParameterInTheConstructorOfPerformanceTracer", operationTitle);
}

Resources