2012-01-24 74 views
1

我已经构建了一个小应用程序。它所做的唯一的事情是,赶上一个传出的电话,并在事件发生时显示一些活动。只有ActivityBroadcastReceiver在BroadcastReceiver中开始活动

我想将我的代码与另一个应用程序集成在一起,我从Manifest.xml中删除了BroadcastReceiver并从主活动中动态创建(并注册)它。我的接收器打得很好,但活动没有出现。

这两种方法有什么区别?

如何让活动显示出来?

MainActivity.java

callInterceptor = new InterceptOutgoingCall(); 
IntentFilter callInterceptorIntentFilter = new IntentFilter("android.intent.action.NEW_OUTGOING_CALL"); 
callInterceptorIntentFilter.setPriority(100); 
registerReceiver(callInterceptor, callInterceptorIntentFilter); 

,并从功能receiver.onReceive(Context,Intent)

Intent alertIntent = new Intent(context, AlertActivity.class); 
alertIntent.putExtra("callnumber", phonenbr); 
alertIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
context.startActivity(alertIntent); 

我的活动在manifest这样宣称:

<activity android:name=".AlertActivity" 
      android:screenOrientation="portrait"/> 

回答