i tried many time but all actually i am creating a setting page i mean a setting button where to handle the on and off in the application class where i extends from the application it show me the Boolean reference null exception. the following is the manifest.
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme"
android:name=".ApplicationClass">
<activity android:name=".SplashScr">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
and this is the java class.
public class ApplicationClass extends Application {
MyService.Reciver rec;
private Context context;
public Boolean getSoundFX_State() {
return soundFX_State;
}
public void setSoundFX_State(Boolean soundFX_State) {
this.soundFX_State = soundFX_State;
}
Boolean soundFX_State;
@Override
public void onCreate()
{
super.onCreate();
regster();
pndng();
setSoundFX_State(true);
}
protected void regster()
{
try {
rec=new MyService().new Reciver();
if(soundFX_State==true) {
registerReceiver(
rec, new IntentFilter(
"android.intent.action.PHONE_STATE"));
Toast.makeText(getBaseContext(), "Your call can disconect automatically", Toast.LENGTH_SHORT)
.show();
}
and the setting.java class.
public class Setting extends Activity {
MyService.Reciver rec;
private CheckBox c1,c2;
protected ApplicationClass app;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.setting);
app=(ApplicationClass)getApplication();
c1=(CheckBox)findViewById(R.id.checkBox);
c2=(CheckBox)findViewById(R.id.checkBox2);
rec=new MyService().new Reciver();
if(app.getSoundFX_State())
{
c1.setChecked(true);
}
else {
c1.setChecked(false);
}
c1.setOnCheckedChangeListener(new CheckBox.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if(isChecked) {
Toast.makeText(getBaseContext(), "c1", Toast.LENGTH_LONG).show();
app.setSoundFX_State(true);
}
else {
app.setSoundFX_State(false);
Toast.makeText(getBaseContext(),"off",Toast.LENGTH_SHORT).show();
}
}
});
c2.setOnCheckedChangeListener(new CheckBox.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
Toast.makeText(getBaseContext(),"c2",Toast.LENGTH_LONG).show();
}
});
{
};
}
public void chkboxclicked(View view)
{
}
}