Last active
February 18, 2021 06:37
-
-
Save doyle-flutter/0f9cc6d6e3e31b01838fed58cdf933b5 to your computer and use it in GitHub Desktop.
#06 백그라운드
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
| // ... import 생략 | |
| public class MyIntentService extends IntentService { | |
| ResultReceiver receiver; | |
| public MyIntentService() { | |
| super("MyIntentService"); | |
| } | |
| @Override | |
| protected void onHandleIntent(Intent intent) { | |
| receiver = intent.getParcelableExtra("INTENT_KEY_RECEIVER"); | |
| Timer m = new Timer(); | |
| TimerTask mt = new TimerTask() { | |
| @Override | |
| public void run() { | |
| URL url = null; | |
| Log.d("DOY","START!"); | |
| try { | |
| Log.d("DOY","START@@"); | |
| url = new URL("http://127.0.0.1:3003/"); | |
| HttpURLConnection httpConn = (HttpURLConnection) url.openConnection(); | |
| BufferedReader reader = new BufferedReader((new InputStreamReader(httpConn.getInputStream(), "UTF-8"))); | |
| String resBodyData = reader.readLine(); | |
| int statusCode = httpConn.getResponseCode(); | |
| Log.d("DOY", resBodyData); | |
| Log.d("DOY", String.valueOf(statusCode)); | |
| if(statusCode == 200){ | |
| Bundle b = new Bundle(); | |
| b.putString("key", resBodyData); | |
| receiver.send(200, b); | |
| } | |
| } catch (IOException e) { | |
| e.printStackTrace(); | |
| } | |
| } | |
| }; | |
| m.schedule(mt,10000); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment