LocalBroadCast를 이용해서 mainActivity Call
mainActivity.java에 statusReceiver define
LocalBroadcastManager.getInstance(this).registerReceiver(
statusReceiver, new IntentFilter("STATUS_CHANGED"));
sub class에서 main call
Intent intent = new Intent("STATUS_CHANGED");
intent.putExtra("status", canShake);
LocalBroadcastManager.getInstance(context).sendBroadcast(intent);
mainActivity에서 response 대응
private final BroadcastReceiver statusReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
// Receive the status change
boolean status = intent.getBooleanExtra("status", true);
if (isShake) {
leftV.setVisibility(View.VISIBLE);
rightV.setVisibility(View.VISIBLE);
isShake = false;
}
}
};
'android source ' 카테고리의 다른 글
textview touch color 변화 (0) | 2024.10.24 |
---|---|
Sound, media 대신 ring mode로 설정 (0) | 2024.10.19 |
PhoneShaking Detect (1) | 2024.09.17 |
String Utility (0) | 2024.09.16 |
Notification 보내기 (0) | 2024.09.16 |