Add this in your build.gradle
compile 'com.amitshekhar.android:android-networking:1.0.2'
When using it with RxJava2
compile 'com.amitshekhar.android:rx2-android-networking:1.0.2'
public class PriorityThreadPoolExecutor extends ThreadPoolExecutor { | |
public PriorityThreadPoolExecutor(int corePoolSize, int maximumPoolSize, long keepAliveTime, | |
TimeUnit unit, ThreadFactory threadFactory) { | |
super(corePoolSize, maximumPoolSize, keepAliveTime, unit,new PriorityBlockingQueue<Runnable>(), threadFactory); | |
} | |
@Override | |
public Future<?> submit(Runnable task) { | |
PriorityFutureTask futureTask = new PriorityFutureTask((PriorityRunnable) task); |
/** | |
* Priority levels | |
*/ | |
public enum Priority { | |
/** | |
* NOTE: DO NOT CHANGE ORDERING OF THOSE CONSTANTS UNDER ANY CIRCUMSTANCES. | |
* Doing so will make ordering incorrect. | |
*/ | |
/** |
/* | |
* Singleton class for default executor supplier | |
*/ | |
public class DefaultExecutorSupplier{ | |
/* | |
* Number of cores to decide the number of threads | |
*/ | |
public static final int NUMBER_OF_CORES = Runtime.getRuntime().availableProcessors(); | |
/* |
// Write this in onBackPress of your MainActivity | |
public class MainActivity extends AppCompatActivity{ | |
@Override | |
public void onBackPressed() { | |
super.onBackPressed(); | |
// This is important : Hack to open a dummy activity for 200-500ms (cannot be noticed by user as it is for 500ms | |
// and transparent floating activity and auto finishes) | |
startActivity(new Intent(this, DummyActivity.class)); | |
finish(); |
<?xml version="1.0" encoding="utf-8"?> | |
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | |
package="com.memory.test"> | |
<application/> | |
<activity | |
android:name=".MainActivity" | |
android:configChanges="orientation|keyboardHidden" | |
android:screenOrientation="portrait"> | |
<intent-filter> |
<resources> | |
<!-- Customize theme for floating. --> | |
<style name="AppTheme.Transparent" parent="Theme.AppCompat.Light.NoActionBar"> | |
<item name="android:windowIsTranslucent">true</item> | |
<item name="android:windowBackground">@android:color/transparent</item> | |
<item name="android:windowContentOverlay">@null</item> | |
<item name="windowNoTitle">true</item> | |
<item name="android:windowIsFloating">true</item> | |
<item name="android:backgroundDimEnabled">false</item> | |
</style> |
package com.memory.test; | |
import android.os.Bundle; | |
import android.os.Handler; | |
import android.support.annotation.Nullable; | |
import android.support.v7.app.AppCompatActivity; | |
/** | |
* Created by amitshekhar on 06/05/16. | |
*/ |