startActivity()
用于方法的意图和用于方法的意图有什么区别sendBroadcast()
?在教程中,我找到了一种动态注册广播接收器的方法。为此,我必须提供一个字符串作为我的意图名称。在这种情况下如何选择一个意图名称并使用 for sendBroadcast()
or registerReceiver()
?
我应该在我的android_manifest.xml
文件中添加一些东西吗?根据教程,我目前已经声明了一个这样的意图名称:
private static final String SEARCH_ACTION = "com.example.usingwebservices.rest.SEARCH";
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
unregisterReceiver(receiver);
}
@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
registerReceiver(receiver, new IntentFilter(SEARCH_ACTION));
}
private BroadcastReceiver receiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
if(progress!=null){
progress.dismiss();
}
String response = intent.getStringExtra(RestTask.HTTP_RESPONSE);
result.setText(response);
}
};