android-handler

Handler(Handler.Callback) is deprecated

拥有回忆 提交于 2020-12-30 02:45:27
问题 Handler(android.os.Handler.Callback) is deprecated what should I use instead? Handler handler = new Handler(new Handler.Callback() { @Override public boolean handleMessage(@NonNull Message message) { switch(message.what) { case READ_MESSAGE: byte[] readBuff = (byte[]) message.obj; String tempMessage = new String(readBuff, 0, message.arg1); readMsg.setText(tempMessage); break; } return true; } }); 回答1: From API level 30, there are 2 constructors are deprecated. Handler() Handler(Handler

Android Handler callback not removed for token type Int or Long (*Kotlin)

戏子无情 提交于 2020-06-23 05:14:51
问题 I have this code executed in Kotlin android project and it will log both messages. If I change the token to Char or String it will print only one message which is the wanted behaviour. Same use-case in a java project in android works as it should. val handler = Handler() //val token1: Long = 1001L //val token2: Int = 121 val token1: Long = 1001L val token2: Int = 1002 handler.postAtTime( { Log.e("postAtTime 1", " printed 1 ") handler.removeCallbacksAndMessages(token2) }, token1, SystemClock

android - how to delay an audio file by a few seconds

强颜欢笑 提交于 2020-02-07 08:57:25
问题 I'm trying to figure out how to delay an audio file by about 15 seconds. The audio file is 5 seconds long and it's a sound effect saying "5,4,3,2,1 go!", the countdown is from 20 so it should start after 15 seconds. I heard I can do this with a handler but I don't know how to implement it in the code, so here it is, help would be much appreciated! I edited it with the way below, however now the player doesn't start at all, here's the new code: public class WorkoutGymEasy1 extends Activity {

Stop handler.postDelayed()

不问归期 提交于 2020-01-18 13:22:23
问题 I call multiple Handlers by new Handler().postDelayed(new Runnable()..... How can I stop it when I click on back? public class MyActivity extends AppCompatActivity implements OnClickListener { private Button btn; private Handler handler; private Runnable myRunnable; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); btn = (Button) findViewById(R.id.trainingsstart); btn.setOnClickListener(this); } @Override public void onClick(View v) { Handler

Stop handler.postDelayed()

会有一股神秘感。 提交于 2020-01-18 13:18:13
问题 I call multiple Handlers by new Handler().postDelayed(new Runnable()..... How can I stop it when I click on back? public class MyActivity extends AppCompatActivity implements OnClickListener { private Button btn; private Handler handler; private Runnable myRunnable; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); btn = (Button) findViewById(R.id.trainingsstart); btn.setOnClickListener(this); } @Override public void onClick(View v) { Handler

Stop handler.postDelayed()

穿精又带淫゛_ 提交于 2020-01-18 13:18:03
问题 I call multiple Handlers by new Handler().postDelayed(new Runnable()..... How can I stop it when I click on back? public class MyActivity extends AppCompatActivity implements OnClickListener { private Button btn; private Handler handler; private Runnable myRunnable; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); btn = (Button) findViewById(R.id.trainingsstart); btn.setOnClickListener(this); } @Override public void onClick(View v) { Handler

Why is my constructor not getting called?

北战南征 提交于 2020-01-16 20:19:23
问题 I'm trying to add some records to a SQLite table, but LogCat is telling me the table does not exist. And DDMS shows that, yes, that table is not being/has not been created. Yet I do create the table in the SQLiteOpenHelper class: public class SQLiteHandlerDeliveryItem extends SQLiteOpenHelper { . . . @Override public void onCreate(SQLiteDatabase sqLiteDatabase) { String CREATE_DELIVERYITEMS_TABLE = "CREATE TABLE " + TABLE_DELIVERYITEMS + "(" + COLUMN_ID + " INTEGER PRIMARY KEY," + COLUMN

Why is my constructor not getting called?

旧巷老猫 提交于 2020-01-16 20:19:23
问题 I'm trying to add some records to a SQLite table, but LogCat is telling me the table does not exist. And DDMS shows that, yes, that table is not being/has not been created. Yet I do create the table in the SQLiteOpenHelper class: public class SQLiteHandlerDeliveryItem extends SQLiteOpenHelper { . . . @Override public void onCreate(SQLiteDatabase sqLiteDatabase) { String CREATE_DELIVERYITEMS_TABLE = "CREATE TABLE " + TABLE_DELIVERYITEMS + "(" + COLUMN_ID + " INTEGER PRIMARY KEY," + COLUMN

AlarmManager or Handler

别来无恙 提交于 2020-01-16 00:49:08
问题 I have specific case to ping my server every 10-60 minutes (it still depends) but only when app is opened. This feature is created to inform that session is still open where session is defined as period from app open to app close. I don't have to worry about process kill. What is better to use ? AlarmManager or Handler .postDelayed() ? The targeted platform is android tv so imagine the case is when watching film in context of my app for example. Personally I first thought to use AlarmManager

Is a Handler a Thread or not, and what is the role of a Looper with Handlers and Threads?

牧云@^-^@ 提交于 2020-01-12 10:17:24
问题 Is a Handler a Thread or not? If yes, how can we update the UI from this Handler(thread)? If we use the Looper concept, it may be possible. In this case, does it apply to any threads? I am very much confused about these Threads, Handlers and Loopers. Could anyone please explain them with an example? Is a Handler a Thread or not? If yes, how can we update the UI from this Handler(thread). If we use the Looper concept, it may be possible, in this case does it apply to any threads? I am very