Thursday, February 16, 2017

AsyncTask & multithreading

Android runs all async tasks in a single thread, which means, if one task is blocking, the other task will need to wait till it finishes.
In some cases you will need you async tasks to run simultaneously.
In such a case use:

Here is an example:
new SomeAsyncTask().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);

Tuesday, January 3, 2017

The Simplest Async Task possible

private class SomeAsyncTask extends AsyncTask<Void, Void, Void> {

    @Override    protected Void doInBackground(Void... voids) {
        Log.d(P.Tag, "doInBackground");
        return null;

Sunday, November 20, 2016

Activity does not have the latest intent information put in the pending intent extras

It happens when the activity is resumed.

You need to:

1. In the intent:
  PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,

  If you have more then one notification at a time, set the request code uniquely

  PendingIntent pendingIntent = PendingIntent.getActivity(this, uniqueIntForName, intent, PendingIntent.FLAG_UPDATE_CURRENT);

  This way you will have the correct extras for the specific notification when lunching the 

2. In the Activity the pending intent is calling:

   public void onNewIntent(Intent newIntent) {
    Log.i(P.Tag, "===onNewIntent called===");

Friday, November 11, 2016

How to uninstall an app from wearable

Android wear connect via Bluetooth

adb forward tcp:4444 localabstract:/adb-hub
adb connect

Uninstall a standalone app

adb -s uninstall com.netcompss.fl_groups

If you want to uninstall a regular app, then just uninstall the phone app, and the wearable app will uninstall automaticly

Friday, October 28, 2016

OK Google beep sound fix

Google decided to remove the beep sound from the OK Google assistant.
Lots of users hate this decision, giving the Google app bad reviews, but Google will not fold.

Here is how to get the beep sound back in a few easy steps:

Setting, accessibility, switch access to on.

Here is a video that shows, the issue, and how to solve it:

Sunday, September 18, 2016

Simple Java Timer (Can be used in Android)

With the default fixed-period execution, each successive run of a task is scheduled relative to the start time of the previous run, so two runs are never fired closer together in time than the specified period. With fixed-rate execution, the start time of each successive run of a task is scheduled without regard for when the previous run took place. This may result in a series of bunched-up runs (one launched immediately after another) if delays prevent the timer from starting tasks on time.

// First run after 2000ms, next run after 1000ms
public static void testTimer() {
Timer timer = new Timer();
timer.schedule(new TimerTask() {
int i = 0;
public void run() {
Random rand = new Random();
int randInt5000 = rand.nextInt(5000);
System.out.println("working : " + randInt5000);
try {
} catch (InterruptedException e) {
// TODO Auto-generated catch block
if (i == 5) timer.cancel();

}, 2000, 1000);


Monday, July 25, 2016

Sending a Toast from a Service

Handler handler = new Handler(Looper.getMainLooper()); Runnable() { @Override public void run()
    Toast.makeText(getApplicationContext(), "Detection Service Failed, restart it", Toast.LENGTH_LONG).show();