(final Context context, final LifecycleOwner owner, final Bundle args, final String name)
| 167 | } |
| 168 | |
| 169 | private void run(final Context context, final LifecycleOwner owner, final Bundle args, final String name) { |
| 170 | this.name = name; |
| 171 | this.started = new Date().getTime(); |
| 172 | |
| 173 | if (Log.isTestRelease()) |
| 174 | Log.breadcrumb("SimpleTask", args); |
| 175 | |
| 176 | for (String key : args.keySet()) { |
| 177 | Object value = args.get(key); |
| 178 | if (value instanceof Spanned) |
| 179 | args.putCharSequence(key, new SpannableStringBuilderEx((Spanned) value)); |
| 180 | } |
| 181 | |
| 182 | if (owner instanceof TwoStateOwner) |
| 183 | Log.e(new Throwable("SimpleTask/TwoStateOwner")); |
| 184 | |
| 185 | // prevent garbage collection |
| 186 | synchronized (tasks) { |
| 187 | if (id != null) |
| 188 | for (SimpleTask task : new ArrayList<>(tasks)) |
| 189 | if (id.equals(task.id)) |
| 190 | task.cancel(context); |
| 191 | tasks.add(this); |
| 192 | } |
| 193 | |
| 194 | try { |
| 195 | onPreExecute(args); |
| 196 | } catch (Throwable ex) { |
| 197 | Log.e(ex); |
| 198 | try { |
| 199 | onException(args, ex); |
| 200 | } catch (Throwable exex) { |
| 201 | Log.e(exex); |
| 202 | } |
| 203 | } |
| 204 | |
| 205 | LifecycleObserver watcher = new LifecycleObserver() { |
| 206 | @OnLifecycleEvent(Lifecycle.Event.ON_DESTROY) |
| 207 | public void onDestroy() { |
| 208 | EntityLog.log(context, EntityLog.Type.Debug1, "Owner gone task=" + name); |
| 209 | destroyed = true; |
| 210 | onDestroyed(args); |
| 211 | owner.getLifecycle().removeObserver(this); |
| 212 | } |
| 213 | }; |
| 214 | |
| 215 | Context tcontext; |
| 216 | if (context instanceof ActivityBase) { |
| 217 | int themeId = ((ActivityBase) context).getThemeId(); |
| 218 | if (themeId == 0) |
| 219 | themeId = context.getApplicationInfo().theme; |
| 220 | tcontext = ApplicationEx.getThemedContext(context, themeId); |
| 221 | } else |
| 222 | tcontext = context.getApplicationContext(); |
| 223 | |
| 224 | future = getExecutor(context).submit(new Runnable() { |
| 225 | private Object data; |
| 226 | private long elapsed; |
no test coverage detected