How To Add Return=true In Wireless Settings
im working on a project and im stuck, what i want is after enabling wifi or internet, the back button(hardware button) should bring me back to SplitScreen.xml instead of closing th
Solution 1:
To achieve the behavior you want, move your call to open Wireless Settings to the MainActivity, and add a boolean variable to its Intent to indicate whether the Settings should be opened in MainActivity.onCreate.
Total Redo Edit
This is your SplashActivity.java. The only problem you should have is the layout name. I don't remember what you named it.
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog.OnClickListener;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;
publicclassSplashScreenextendsActivity
{
static ConnectivityManager cm;
AlertDialog dailog;
AlertDialog.Builder build;
@OverrideprotectedvoidonCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);// checking
build = newAlertDialog.Builder(this);
setContentView(R.layout.activity_splash);
// if connection is// there screen goes// to next screen// else shows// messageif (cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI).isConnectedOrConnecting()
|| cm.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).isConnectedOrConnecting())
{
Log.e("cm value", "" + cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI)
.isConnectedOrConnecting());
Toast.makeText(this, "Internet is active", 2000).show();
Threadmythread=newThread() {
publicvoidrun()
{
try
{
sleep(5000);
}
catch (Exception e)
{
}
finally
{
Intentintent=newIntent(SplashScreen.this,
MainActivity.class);
startActivity(intent);
finish();
}
}
};
mythread.start();
}
else
{
build.setMessage("This application requires Internet connection. Would you connect to internet ?");
build.setPositiveButton("Yes", newOnClickListener() {
@OverridepublicvoidonClick(DialogInterface dialog, int which)
{
// TODO Auto-generated method stubIntentintent=newIntent(SplashScreen.this,
MainActivity.class);
intent.putExtra("showSettings", true);
startActivity(intent);
finish();
//startActivity(new Intent(Settings.ACTION_WIRELESS_SETTINGS));
}
});
build.setNegativeButton("No", newOnClickListener() {
@OverridepublicvoidonClick(DialogInterface dialog, int which)
{
// TODO Auto-generated method stub
build.setMessage("Are sure you want to exit?");
build.setPositiveButton("Yes", newOnClickListener() {
@OverridepublicvoidonClick(DialogInterface dialog, int which)
{
// TODO Auto-generated method stub
finish();
}
});
build.setNegativeButton("NO", newOnClickListener() {
@OverridepublicvoidonClick(DialogInterface dialog, int which)
{
// TODO Auto-generated method stub
finish();
Intentintent=newIntent(SplashScreen.this,
SplashScreen.class);
startActivity(intent);
dialog.dismiss();
}
});
dailog = build.create();
dailog.show();
}
});
dailog = build.create();
dailog.show();
}
}
}
And this is your MainActivity.
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.provider.Settings;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;
import android.widget.ToggleButton;
import android.widget.Toast;
publicclassMainActivityextendsActivity
{
ToggleButton toggle;
@OverridepublicvoidonCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
toggle = (ToggleButton)findViewById(R.id.tglbtn1);
toggle.setOnClickListener(newOnClickListener()
{
publicvoidonClick(View v)
{
if (toggle.isChecked())
{
Toast.makeText(getApplicationContext(), "Boosting For Next 60 Minutes, Minimize the Application", Toast.LENGTH_LONG).show();
}
else
{
Toast.makeText(getApplicationContext(), "Boosting Turned Off", Toast.LENGTH_LONG).show();
}
}
}
);
Intentintent= getIntent();
booleanshow= intent.getBooleanExtra("showSettings", false);
if (show)
{
startActivity(newIntent(Settings.ACTION_WIRELESS_SETTINGS));
}
}
}
Fix the layout name issue in SplashScreen and you should be good. I just ran this code and it performs as expected.
Post a Comment for "How To Add Return=true In Wireless Settings"