Please use AsyncTask similar to this code https://github.com/osmandapp/Osmand/blob/master/OsmAnd/src/net/osmand/plus/base/FailSafeFuntions.java#L111