Network
クラス(非アクティビティクラス)からトーストを表示するために、次の変更を行います。
ステップ:1アクティビティコンテキストを次の代わりにネットワーククラスに渡しgetBaseContext()
ます:
netConnection = new Network(new Network.OnMessageReceived() {
@Override
// here the messageReceived method is implemented
public void messageReceived(String message) {
// this method calls the onProgressUpdate
publishProgress(message);
}
},Your_Current_Activity_Name.this);
ステップ2:runOnUiThread
ネットワーククラスからトーストを表示するために使用します:
public boolean connect() {
//....your code..
Activity activity = (Activity) context;
activity.runOnUiThread(new Runnable() {
public void run() {
//show your Toast here..
Toast.makeText(context,"Connection Successful", Toast.LENGTH_LONG).show();
}
});
//....your code..
}