2

I want to make the hand phone continuously refresh the RSSI values of other devices while the phone is being moved away from them.

In order to make the screen display keep updating the new RSSI values, I choose to use AsyncTask so as not to freeze my UI.

But somehow my code does not work. Every time it is run, the app dies. For debugging purpose, I put a Toast.makeText there. But nothing appears on the screen. So maybe that means my AsyncTask is actually not executed at all?

AsyncTask Codes:

    private class Refresh extends AsyncTask<Void, Void, Void> {
    @Override
    protected Void doInBackground(Void... params) {
        // TODO Auto-generated method stub
        while(true){
            Toast.makeText(getApplicationContext(), "Loop is being executed", Toast.LENGTH_SHORT).show();
            init();
            startDiscovery();
        }
    }
}

OnCreat() Codes:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    init();
    startDiscovery();

    new Refresh().execute();
}

Do please help me! Where am I wrong?

ToT

4

0 に答える 0