通话结束后,在主屏幕上打开半屏活动

时间:2013-06-05 10:44:14

标签: android

我正在尝试打开一个活动,它将覆盖Home Scree的半屏幕。 它将由BroadcastReceiver调用,它将在呼叫结束时触发。 我面临的问题是它在后台打开MAIN活动,我无法进入主屏幕。

以下是代码:

public class IncomingCallInterceptor extends BroadcastReceiver {                                    // 1

@Override
public void onReceive(Context context, Intent intent) {                                         // 2
    String state = intent.getStringExtra(TelephonyManager.EXTRA_STATE);                         // 3

    if (TelephonyManager.EXTRA_STATE_IDLE.equals(state)) {                                  // 4
        Intent intent_new=new Intent(context, HalfScreen.class);
        intent_new.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent_new.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
        context.startActivity(intent_new);
     }
   } 
} 

活动类:

public class AddAppointmentHomeScreenActivity extends Activity {

@Override
protected void onCreate(Bundle bundle) {
    super.onCreate(bundle);
    setContentView(R.layout.add_appointment_home_screen_activity);
}

}

add_appointment_home_screen_activity.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:windowAnimationStyle="@android:style/Animation.Translucent"
android:windowBackground="@android:color/transparent"
android:windowIsTranslucent="true"
android:orientation="vertical" >

<Button
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:layout_marginBottom="24dp"
    android:layout_marginLeft="72dp"
    android:text="Button" />
</RelativeLayout>

清单文件:

<activity android:name=".AddAppointmentHomeScreenActivity" ></activity>

如果需要更多详细信息,请与我们联系。

public class AddAppointmentHomeScreenActivity extends Activity {

@Override
protected void onCreate(Bundle bundle) {
    super.onCreate(bundle);
    setContentView(R.layout.add_appointment_home_screen_activity);
}

}

0 个答案:

没有答案