Android 在运行时完成意图活动

Android 在运行时完成意图活动,android,android-intent,android-activity,Android,Android Intent,Android Activity,我有一个动作调用意图活动,我想用代码停止它 问题存在于2.3.3,当我结束通话时,它会转到通话日志,而不是直接返回到4.1+上的应用程序 我发现您可以使用finishActivityrequestCode来完成一个对我的代码不起作用的活动 这是我的密码: startActivityForResult(callIntent, 2); // when I call finishActivity here it works fine and activity ends immedi

我有一个动作调用意图活动,我想用代码停止它

问题存在于2.3.3,当我结束通话时,它会转到通话日志,而不是直接返回到4.1+上的应用程序

我发现您可以使用finishActivityrequestCode来完成一个对我的代码不起作用的活动

这是我的密码:

    startActivityForResult(callIntent, 2);


    // when I call finishActivity here it works fine and activity ends immediately
    // finishActivity(2);

    if (endCall) 
    {
        callEndTimer = new CountDownTimer(10000, 1000) //End call after 10 seconds
        {
            public void onTick(long millisUntilFinished)
            {

            }

            public void onFinish()
            {
                // end the call

                TelephonyManager tm = (TelephonyManager) getApplicationContext().getSystemService(
                        Context.TELEPHONY_SERVICE);

                Class<?> c;
                try
                {
                    c = Class.forName(tm.getClass().getName());
                    Method m = c.getDeclaredMethod("getITelephony");
                    m.setAccessible(true);
                    Object telephonyService = m.invoke(tm);
                    c = Class.forName(telephonyService.getClass().getName());
                    m = c.getDeclaredMethod("endCall");
                    m.setAccessible(true);
                    m.invoke(telephonyService);

                    // Call ends here so I know the code is working
                    // When I call finishActivity(2) here the activity doesn't end and continues to go to the call logs
                    finishActivity(2);

                } catch (Exception e)
                {
                    e.printStackTrace();
                }
            }
        }.start();
    }

关于为什么我不能结束活动有什么想法吗?

如果你在课堂上扩展活动,只要在你想停止活动的地方调用finish即可。

它扩展了ActionBarActivity。调用finish完成我的主要活动,而不是调用意图活动,因此它不能解决问题。