我有2個類。在ConnectThread的結尾,我想打開一個新的活動。這個代碼我在StackOverflow上找到,但它並沒有工作。誰能告訴我如何解決這個問題。如何從線程中打開活動
public class MainActivity extends Activity {
// some code
}
class ConnectThread extends Thread {
Handler handler = new Handler(Looper.getMainLooper());
public ConnectThread(BluetoothDevice device) {
// some code
}
public void run() {
// some code
handler.post(new Runnable() {
@Override
public void run() {
Intent startPostGet = new Intent(MainActivity.this, PostGetActivity.class);
startActivity(startPostGet);
}
});
}
}
如何以及在何處使用ConnectThread?看來ConnectThread沒有上下文MainActivity – SorryForMyEnglish