Skip to content

Commit e89bfae

Browse files
authored
Merge pull request #2613 from Neamar/looper-handler
Stop using Handler() without the main looper
2 parents 083f0f2 + f5464ec commit e89bfae

3 files changed

Lines changed: 7 additions & 4 deletions

File tree

app/src/main/java/fr/neamar/kiss/DataHandler.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import android.os.Build;
1414
import android.os.Handler;
1515
import android.os.IBinder;
16+
import android.os.Looper;
1617
import android.os.UserManager;
1718
import android.text.TextUtils;
1819
import android.util.Pair;
@@ -234,7 +235,7 @@ public void onReceive(final Context context, Intent intent) {
234235
boolean isPhoneLocked = myKM.inKeyguardRestrictedInputMode();
235236
if (!isPhoneLocked) {
236237
context.unregisterReceiver(this);
237-
final Handler handler = new Handler();
238+
final Handler handler = new Handler(Looper.getMainLooper());
238239
// Even when all the stars are aligned,
239240
// starting the service needs to be slightly delayed because the Intent is fired *before* the app is considered in the foreground.
240241
// Each new release of Android manages to make the developer life harder.

app/src/main/java/fr/neamar/kiss/forwarder/Widgets.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import android.content.Intent;
1414
import android.os.Build;
1515
import android.os.Handler;
16+
import android.os.Looper;
1617
import android.os.UserHandle;
1718
import android.text.TextUtils;
1819
import android.view.ContextMenu;
@@ -437,7 +438,7 @@ private void requestBindWidget(@NonNull Intent data) {
437438
final ComponentName provider = data.getParcelableExtra(AppWidgetManager.EXTRA_APPWIDGET_PROVIDER);
438439
final UserHandle profile = data.getParcelableExtra(AppWidgetManager.EXTRA_APPWIDGET_PROVIDER_PROFILE);
439440

440-
new Handler().postDelayed(() -> {
441+
new Handler(Looper.getMainLooper()).postDelayed(() -> {
441442
Log.d(TAG, "asking for permission");
442443

443444
Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_BIND);

app/src/main/java/fr/neamar/kiss/result/Result.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import android.graphics.Typeface;
1010
import android.graphics.drawable.Drawable;
1111
import android.os.Handler;
12+
import android.os.Looper;
1213
import android.text.Spannable;
1314
import android.text.SpannableString;
1415
import android.text.style.ForegroundColorSpan;
@@ -395,7 +396,7 @@ protected final void recordLaunch(Context context, @Nullable QueryInterface quer
395396
// * to ensure the animation runs smoothly
396397
// * to avoid a flickering -- launchOccurred will refresh the list
397398
// Thus TOUCH_DELAY * 3
398-
Handler handler = new Handler();
399+
Handler handler = new Handler(Looper.getMainLooper());
399400
handler.postDelayed(() -> {
400401
if (queryInterface != null) {
401402
queryInterface.launchOccurred();
@@ -596,7 +597,7 @@ protected void setTranscriptModeAlwaysScroll(RecordAdapter adapter) {
596597
// We'll need to reset the list view to its previous transcript mode,
597598
// but it has to happen *after* the keyboard is hidden, otherwise scroll will be reset
598599
// Let's wait for half a second, that's ugly but we don't have any other option :(
599-
final Handler handler = new Handler();
600+
final Handler handler = new Handler(Looper.getMainLooper());
600601
handler.postDelayed(() -> adapter.updateTranscriptMode(AbsListView.TRANSCRIPT_MODE_ALWAYS_SCROLL), 500);
601602
}
602603

0 commit comments

Comments
 (0)