안드로이드 개발 질문/답변
(글 수 45,052)
일단 브로드캐스트 리시버 활용을 위해 간단한 예제를 구성해 보았는데요 전혀 반응을 하지 않아 질문드립니다.
- 일단 제가 반응할 놈은 ACTION_TIME_TICK 입니다. 레퍼런스를 참고하면 매분 마다 방송된다고 하길래 청취를 시도했습니다.
http://d.android.com/reference/android/content/Intent.html#ACTION_TIME_TICK
manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.arcadia"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".Start"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name="org.arcadia.MyReceiver">
<intent-filter>
<action android:name="android.intent.action.TIME_TICK"/>
</intent-filter>
</receiver>
</application>
<uses-sdk android:minSdkVersion="7" />
</manifest>
MyReceiver.java
public class MyReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if(intent.getAction().equals(Intent.ACTION_TIME_TICK)) {
//Log.d(this.getClass().getName(), "check");
Toast.makeText(context, "Received", Toast.LENGTH_SHORT).show();
}
}
}
그런데...아무 반응이 없네요..-_-;;
혹시 뭐 빠뜨린게 있는지..-0-;;
답변부탁드립니다.
하나 추가하자면....
Start.java
public class Start extends Activity{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(Intent.ACTION_TIME_TICK);
registerReceiver(new MyReceiver(), intentFilter);
}
}
위 처럼 동적으로 리시버를 등록할 경우 해당 방송에 대한 응답을 보입니다.
그런데 해당 Activity가 종료될경우 에러가 발생하면서..더이상 청취를 하지않습니다.
이 이유도 궁금하네요..
좋은 하루 보내세요~(__)




자답...레퍼런스를 대충본 폐혜네요..;; 동적으로 등록하지 않으면 청취할 수 없다고 나오네요;;
하지만 액티비티 종료시 왜 에러가 발생하는지는 아직도 모르겠네용;;