How to create a Looper thread, then send it a message immediately?

Eventual solution (minus error checking), thanks to CommonsWare: class Worker extends HandlerThread { // … public synchronized void waitUntilReady() { d_handler = new Handler(getLooper(), d_messageHandler); } } And from the main thread: Worker worker = new Worker(); worker.start(); worker.waitUntilReady(); // <- ADDED worker.handler.sendMessage(…); This works thanks to the semantics of HandlerThread.getLooper() which blocks until the … Read more

Moving a custom configuration group to a separate file

As far as I know, you cannot externalize an entire SectionGroup (i.e. MyCustomGroup) using the configSource attribute, but you have to handle this on the Section level (i.e. MyCustomSection) <configuration> <configSections> <sectionGroup name=”MyCustomGroup”> <section name=”MyCustomSection”/> </sectionGroup> </configSections> <MyCustomGroup> <MyCustomSection configSource=”externalfile.config” /> </MyCustomGroup> </configuration> The external file externalfile.config would then contain your actual config settings, starting … Read more

Run Handler messages in a background thread

You can simply do this: private Handler mHandler; private HandlerThread mHandlerThread; public void startHandlerThread(){ mHandlerThread = new HandlerThread(“HandlerThread”); mHandlerThread.start(); mHandler = new Handler(mHandlerThread.getLooper()); } Then invoke with: mHandler.postDelayed(new Runnable() { @Override public void run() { // Your task goes here } },1000);

Solr – Query over all fields best practice

The best solution is to build a field, that collects the data of all fields like this <field name=”collector” type=”text_general” indexed=”true” stored=”false” multiValued=”true” /> The only thing you have to do now is, copy the contents of all fields into that field: <copyField source=”notes” dest=”collector”/> <copyField source=”missionFocus” dest=”collector”/> <copyField source=”name” dest=”collector”/> …. Be aware that … Read more

Web API – 405 – The requested resource does not support http method ‘PUT’

Are you using attribute routing? This mystic error was a route attributes issue. This is enabled in your WebAPIConfig as: config.MapHttpAttributeRoutes(); It turns out Web Api Controllers “cannot host a mixture of verb-based action methods and traditional action name routing. “; https://aspnetwebstack.codeplex.com/workitem/184 in a nutshell: I needed to mark all of my actions in my … Read more

Why to use Handlers while runOnUiThread does the same?

Activity.runOnUiThread() is a special case of more generic Handlers. With Handler you can create your own event query within your own thread. Using Handlers instantiated with the default constructor doesn’t mean “code will run on UI thread” in general. By default, handlers are bound to the Thread from which they were instantiated from. To create … Read more

Completion handler for UINavigationController “pushViewController:animated”?

See par’s answer for another and more up to date solution UINavigationController animations are run with CoreAnimation, so it would make sense to encapsulate the code within CATransaction and thus set a completion block. Swift: For swift I suggest creating an extension as such extension UINavigationController { public func pushViewController(viewController: UIViewController, animated: Bool, completion: @escaping … Read more

Open Internet Explorer from Chrome using a protocol handler (ie:url)

Create a Protocol Handler save this script as internet-explorer-protocol-handler.reg: Windows Registry Editor Version 5.00 [HKEY_CURRENT_USER\Software\Classes\ie] “URL Protocol”=”\”\”” @=”\”URL:IE Protocol\”” [HKEY_CURRENT_USER\Software\Classes\ie\DefaultIcon] @=”\”explorer.exe,1\”” [HKEY_CURRENT_USER\Software\Classes\ie\shell] [HKEY_CURRENT_USER\Software\Classes\ie\shell\open] [HKEY_CURRENT_USER\Software\Classes\ie\shell\open\command] @=”cmd /k set myvar=%1 & call set myvar=%%myvar:ie:=%% & call \”C:\\Program Files (x86)\\Internet Explorer\\iexplore.exe\” %%myvar%% & exit /B” Then run the script to install the keys in your registry. It will … Read more