I have a problem regarding Signal strength value.
I want to put the signal strength value inside the onCreate function but
it gives me zero value. But when I test it inside PhoneStateListener it gives me a value
which is 7.
Any Idea? here is my code.
package com.example.activitylifecycle;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;
import android.util.Log;
public class ActivitySignal extends Activity {
private static final String TAG = "ActivitySignal";
private int signalAsu = 0;
PhoneStateListener signalListener=new PhoneStateListener()
{
public void onSignalStrengthChanged(int asu)
{
Log.d(TAG, "SignalStrength: " + String.valueOf(asu)); // It gives me a value which is 7
signalAsu = asu;
}
};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TelephonyManager SignalManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
SignalManager.listen(signalListener,PhoneStateListener.LISTEN_SIGNAL_STRENGTH);
//another log test
Log.d(TAG, "SignalStrength: " + String.valueOf(signalAsu)); // zero value..
}
}