일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 |
- vscode
- mysql
- 16197
- github
- Jenknis
- 큐빙
- 안드로이드
- git
- IntelliJ
- intent
- 데이터
- 백준
- Algorithm
- insert
- ubuntu
- 17837
- 두 동전
- 알고리즘
- 단축키
- broadcastreceiver
- Android
- data
- spring
- 제어반전
- 데이터전달
- 프로그래머스
- service
- Java
- goland
- activity
- Today
- Total
목록데이터전달 (3)
해보자
Service → Activity ____Service.java 1 2 3 4 Intent intent = new Intent(getApplicationContext(), ____Activity.class); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.putExtra("id", id); startActivity(intent); ____Activity.java 1 2 Intent a_intent= getIntent(); String id = intent.getStringExtra("id");
BroadcastReceiver → Service ___Receiver.java Intent intent = new Intent(context, ____Service.class); intent.putExtra("id", id ); this.context.startService(intent); ___Service.java @Override public int onStartCommand(Intent intent, int flags, int startId) { String id = intent.getStringExtra("id"); return super.onStartCommand(intent, flags, startId); }
Activity → BroadcastReceiver ____Activity.java intent = new Intent(this, ____Receiver.class); String id; intent.putExtra("id", id); sendBroadcast(intent); ____Receiver.java @Override public void onReceive(Context context, Intent intent) { String id = intent.getStringExtra("id"); }