收到呼叫时应用程序崩溃

时间:2014-08-19 10:19:17

标签: java android telephonymanager

我正在开发一个Android应用程序。我的问题是,当一个呼叫到达时,应用程序崩溃。

                @Override
                    public void onRestart(){
                        Log.d(WebServiceHelper.TAG, "Dashboard onRestart---------------->");
                        super.onRestart();
                        Intent intent = new Intent(this,DashBoard.class);
                        startActivity(intent);
                        finish();
                    }

我使用了这个代码来重启DashBoard活动             我还使用了一个Endcall列表器来处理电话             这是代码

            public class EndCallListener extends PhoneStateListener {
              private boolean active = false;
              //EndCallListener context=this;
              private Context _context;
              public EndCallListener(Context context){
                    this._context = context;

              }
              @Override
              public void onCallStateChanged(int state, String incomingNumber) {
                if(TelephonyManager.CALL_STATE_RINGING == state) {
                  Log.i("EndCallListener", "RINGING, number: " + incomingNumber);
                }
                if(TelephonyManager.CALL_STATE_OFFHOOK == state) {
                  //wait for phone to go offhook (probably set a boolean flag) so you know your app initiated the call.
                  active = true;
                  Log.i("EndCallListener", "OFFHOOK");
                }
                if(TelephonyManager.CALL_STATE_IDLE == state) {
                  //when this state occurs, and your flag is set, restart your app
                  Log.i("EndCallListener", "IDLE");
                  if (active) {
                    active = false;
                    // stop listening                   
                    TelephonyManager mTM = (TelephonyManager)_context.getSystemService(Context.TELEPHONY_SERVICE);
                    mTM.listen(this, PhoneStateListener.LISTEN_NONE);
                    // restart the inbox activity
                   Intent intent = new Intent(_context, DashBoard.class);
                   _context.startActivity(intent);
                  }
                }
              }
            }

我使用

调用endcalllistner
        EndCallListener callListener = new EndCallListener(this);
                    TelephonyManager mTM = (TelephonyManager) this
                            .getSystemService(Context.TELEPHONY_SERVICE);
                    mTM.listen(callListener, PhoneStateListener.LISTEN_CALL_STATE);

请帮帮我。怎么解决这个问题? 提前致谢

    08-19 15:58:57.215: E/ActivityThread(14434): Performing stop of activity that is not resumed: {com.exalt.vts/com.exalt.vts.DashBoard}
    08-19 15:58:57.215: E/ActivityThread(14434): java.lang.RuntimeException: Performing stop of activity that is not resumed: {com.exalt.vts/com.exalt.vts.DashBoard}
    08-19 15:58:57.215: E/ActivityThread(14434):    at android.app.ActivityThread.performStopActivityInner(ActivityThread.java:3167)
    08-19 15:58:57.215: E/ActivityThread(14434):    at android.app.ActivityThread.handleStopActivity(ActivityThread.java:3254)
    08-19 15:58:57.215: E/ActivityThread(14434):    at android.app.ActivityThread.access$1100(ActivityThread.java:145)
    08-19 15:58:57.215: E/ActivityThread(14434):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1233)
    08-19 15:58:57.215: E/ActivityThread(14434):    at android.os.Handler.dispatchMessage(Handler.java:102)
    08-19 15:58:57.215: E/ActivityThread(14434):    at android.os.Looper.loop(Looper.java:136)
    08-19 15:58:57.215: E/ActivityThread(14434):    at android.app.ActivityThread.main(ActivityThread.java:5081)
    08-19 15:58:57.215: E/ActivityThread(14434):    at java.lang.reflect.Method.invokeNative(Native Method)
    08-19 15:58:57.215: E/ActivityThread(14434):    at java.lang.reflect.Method.invoke(Method.java:515)
    08-19 15:58:57.215: E/ActivityThread(14434):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:781)
    08-19 15:58:57.215: E/ActivityThread(14434):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
    08-19 15:58:57.215: E/ActivityThread(14434):    at dalvik.system.NativeStart.main(Native Method)

这是logcat输出 我的清单文件是          

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="com.exalt.asapmobileap.permission.MAPS_RECEIVE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
 <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
 <uses-permission android:name="android.permission.READ_PHONE_STATE" />
 <uses-permission android:name="android.permission.CALL_PHONE" />
 <!-- GCM requires a Google account. -->
    <uses-permission android:name="android.permission.GET_ACCOUNTS" />

    <!-- Keeps the processor from sleeping when a message is received. -->
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <supports-screens
                android:resizeable="true"
        android:anyDensity="true"
        android:largeScreens="true"
        android:normalScreens="true"
        android:smallScreens="true"
        android:xlargeScreens="true" />

    <!-- Creates a custom permission so only this app can receive its messages. -->
    <permission
        android:name="com.exalt.vts.permission.C2D_MESSAGE"
        android:protectionLevel="signature" />

    <uses-permission android:name="com.exalt.vts.permission.C2D_MESSAGE" />

    <!-- This app has permission to register and receive data message. -->
    <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />

    <!-- Network State Permissions to detect Internet status -->
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

    <!-- Permission to vibrate -->
    <uses-permission android:name="android.permission.VIBRATE" />

    <uses-feature
        android:glEsVersion="0x00020000"
        android:required="true" />
    <uses-permission android:name="android.permission.CALL_PHONE" />  

    <uses-sdk
        android:minSdkVersion="11"
        android:targetSdkVersion="18" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/vts_icon"
        android:label="@string/app_name"
        android:theme="@style/AppTheme"

        >
<uses-library android:name="com.google.android.maps" />
        <activity
            android:name="com.exalt.vts.SplashScreen"
            android:label="@string/app_name"

            android:windowSoftInputMode="stateHidden"
             >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name="com.exalt.vts.MainActivity"            


             >

        </activity>
        <activity
            android:name="com.exalt.vts.VTS_LiveTracking"            
            android:label="Live Tracking"

             >

        </activity>

        <activity
            android:name="com.exalt.vts.VTS_LiveReport"
            android:label="@string/app_name"
             >

        </activity>
        <activity
            android:name="com.exalt.vts.EnableNotification"
            android:label="Settings"
             >

        </activity>
        <activity
            android:name="com.exalt.vts.ViewAllNotifications"
            android:label="Notification List"
             >

        </activity>
         <!-- <activity
            android:name="com.exalt.vts.DailyReport"
            android:label="Daily Report"
             >

        </activity> -->
         <activity
            android:name="com.exalt.vts.NavigationDrawerActivity"
            android:label="@string/app_name"
             >

        </activity>
         <activity
            android:name="com.exalt.vts.DashBoard"
            android:label="Dashboard"

             >

        </activity>
        <activity
            android:name="com.exalt.vts.MonthlyReport"
            android:label="Monthly Report"
             >

        </activity>
         <activity
            android:name="com.exalt.vts.Promotions"
            android:label="Promotions"
             >

        </activity>
        <!-- <activity
            android:name="com.exalt.vts.TripReport"
            android:label="Trip Report"
             >

        </activity> -->
        <activity
            android:name="com.exalt.vts.MoretripDetails"
            android:label="@string/app_name"
             >

        </activity>
         <activity
            android:name="com.exalt.vts.VehicleLogReport"
            android:label="@string/app_name"
             >

        </activity>
        <activity
            android:name="com.exalt.vts.ReportNavigationActivity"
            android:label="@string/app_name"
             >

        </activity>
         <activity
            android:name="com.exalt.vts.Tracking"
            android:label="Live Tracking"
             >

        </activity>
        <activity
            android:name="com.exalt.vts.DriverProfile"
            android:label="Driver Profile"
             >

        </activity>
         <activity
            android:name="com.exalt.vts.Vehicle_Profile"
            android:label="Vehicle Profile"
             >

        </activity>
         <activity
            android:name="com.exalt.vts.Vehicle_Profile_DistanceTravelled"
            android:label="Distance"
             >

        </activity>
        <activity
            android:name="com.exalt.vts.VTS_Maintanence_Log"
            android:label="Maintanence Log"
             >

        </activity>
        <activity android:name="org.achartengine.GraphicalActivity" />
        <activity
            android:name="com.exalt.vts.General_Stat_Driver_Prof"
            android:label="General Statistics"
             >

        </activity>
        <activity
            android:name="com.exalt.vts.Gen_Stat_Veh_Prof"
            android:label="General Statistics"
             >

        </activity>
         <activity
            android:name="com.exalt.vts.TripReport_New"
            android:label="Trip Report"
             >

        </activity>
        <activity
            android:name="com.exalt.vts.Daily_Report_New"
            android:label="Daily Report"
             >

        </activity>

        <activity
            android:name="com.exalt.vts.DriverLog"
            android:label="Driver Log"
             >

        </activity>
        <activity
            android:name="com.exalt.vts.DriverPerformance"
            android:label="Driver Performance"
             >

        </activity>
        <activity
            android:name="com.exalt.vts.VehicleLog"
            android:label="Vehicle Log"
             >

        </activity>
        <activity
            android:name="com.exalt.vts.TripDetails_DriverProfile"
            android:label="Trip Details"
             >

        </activity>
        <activity
            android:name="com.exalt.vts.TripDetails_VehicleProfile"
            android:label="Trip Details"
             >

        </activity>

        <meta-data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />  

         <meta-data
            android:name="com.google.android.maps.v2.API_KEY"
            android:value="AIzaSyDBMhM-Fva8RPSVDssI7W50YeopywShD-M" />
         <!-- key Exalt -->
        <receiver
            android:name="com.google.android.gcm.GCMBroadcastReceiver"
            android:permission="com.google.android.c2dm.permission.SEND" >
            <intent-filter>

                <!-- Receives the actual messages. -->
                <action android:name="com.google.android.c2dm.intent.RECEIVE" />
                <!-- Receives the registration id. -->
                <action android:name="com.google.android.c2dm.intent.REGISTRATION" />

                <category android:name="com.exalt.vts" />
            </intent-filter>
        </receiver>
        <service android:name=".GCMIntentService" />
    </application>

</manifest>

0 个答案:

没有答案