Last active
February 8, 2017 10:23
-
-
Save aindong/06737ccaa482d5c9e79391fae03173bf to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Create a new interface | |
public interface UIUpdatable { | |
public void updateUI(String message); | |
} | |
// Implement the new interface on the activity | |
public class QuestionNew extends AppCompatActivity implements UIUpdatable { | |
public TextView txtView; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
txtView = findViewById(R.id.txt_view); | |
// inject this activity to the async test | |
new CCListener(this).execute(new String[]{"AnyData"}); // start your task | |
} | |
// method that comes from the interface | |
@Override | |
public void updateUI(String str) { | |
txtView.setText(str); | |
} | |
} | |
// Your async task | |
public class CCListener extends AsyncTask<Void, Void, Void> { | |
UIUpdatable uiUpdatable; | |
// Constructor, dependency injection | |
public AsyncTest(Activity activity){ | |
uiUpdatable = (UIUpdatable)activity; | |
} | |
@Override | |
protected void onPostExecute(String result) { | |
super.onPostExecute(result); | |
uiUpdatable.updateUI(result); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment