Skip to content

Instantly share code, notes, and snippets.

@doyle-flutter
Last active February 19, 2021 04:54
Show Gist options
  • Save doyle-flutter/01a74e36b054e8ff087a46a3b48c7cd6 to your computer and use it in GitHub Desktop.
Save doyle-flutter/01a74e36b054e8ff087a46a3b48c7cd6 to your computer and use it in GitHub Desktop.
#07 포그라운드 - 안드로이드 : 액티비티
// ... import 생략
// 백그라운코드에 추가하였습니다
public class MainActivity3 extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main3);
ConstraintLayout c = (ConstraintLayout) findViewById(R.id.main3);
ResultReceiver mRecevier = new ResultReceiver(new Handler()){
@Override
protected void onReceiveResult(int resultCode, Bundle resultData) {
super.onReceiveResult(resultCode, resultData);
Log.d("DOY", resultData.getString("key"));
}
};
// intentService 실행
Button backButton = new Button(this.getApplicationContext());
backButton.setText("포그라운드");
final Intent intent = new Intent(this, MyIntentService.class);
intent.putExtra("INTENT_KEY_RECEIVER",mRecevier);
// 포그라운드 서비스 실행
final Intent forIntent = new Intent(this, MyService.class);
forIntent.setAction("startForeground");
View.OnClickListener backButtonListener = new View.OnClickListener() {
@Override
public void onClick(View view) {
Log.d("DOY", "CLICK?");
// - intentService
// startService(intent);
// - ForgroundService
startForegroundService(forIntent);
}
};
backButton.setOnClickListener(backButtonListener);
c.addView(backButton);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment