每个进程多次调用隐藏构造函数



我在我的logcat中得到了这个错误

TelephonyManager : Hidden constructor called more than once per process!

我的PhoneListener不工作

@Override
public void onCallStateChanged(int state, String incomingNumber) {
                        switch (state) {
                        case TelephonyManager.CALL_STATE_IDLE:
                            Log.e("state", "idle");
                            break;
                        case TelephonyManager.DATA_CONNECTED:
                            Log.e("state", "connected");
                            break;
                        }
                    };
                };
    telManager = (TelephonyManager) context
            .getSystemService(Context.TELEPHONY_SERVICE);
    telManager.listen(callListener, PhoneStateListener.LISTEN_CALL_STATE);

它不会打印我的日志。

从源代码中我得到了这个:

/**提供对设备上电话服务信息的访问。应用程序可以使用该类中的方法来确定电话服务和状态,以及访问某些类型的用户信息。应用程序还可以注册一个侦听器来接收电话状态更改的通知。

你不直接实例化这个类;相反,您可以通过{@link android.content检索对实例的引用。上下文# getSystemService Context.getSystemService (Context.TELEPHONY_SERVICE)}。*

注意,对某些电话信息的访问是受许可保护的。您的应用程序不能访问受保护的*信息,除非它具有在其清单文件中声明的适当权限。当权限适用时,它们会在您访问受保护信息的方法中注明。* */

public class TelephonyManager {
private static final String TAG = "TelephonyManager";
private static Context sContext;
private static ITelephonyRegistry sRegistry;
/** @hide */
public TelephonyManager(Context context) {
    context = context.getApplicationContext();
    if (sContext == null) {
        sContext = context;
        sRegistry = ITelephonyRegistry.Stub.asInterface(ServiceManager.getService(
                "telephony.registry"));
    } else if (sContext != context) {
        Log.e(TAG, "Hidden constructor called more than once per process!");
        Log.e(TAG, "Original: " + sContext.getPackageName() + ", new: " +
                context.getPackageName());
    }
}

您是否从不同的上下文中创建telephonymanager的多个实例?如果是,那么错误日志将显示上下文是静态的。

最新更新