Note that there are some explanatory texts on larger screens.

plurals
  1. POcan't return to activity after System settings intent
    primarykey
    data
    text
    <p>In my applicattion i need to go to de settings activity of the phone to activate GPS and want to return to my application using this code code:</p> <p><code>Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS); startActivityForResult(intent);</code></p> <p>but when I used it I couldn't return to my app. when I pressed back so I tried this :</p> <pre><code> Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS); startActivityForResult(intent, 0); </code></pre> <p>then I called all types of result in this code </p> <pre><code> public void onActivityResult(int requestCode, int resultCode, Intent x){ if(requestCode == 0){ if(resultCode == RESULT_CANCELED){ Button b = (Button)findViewById(R.id.button1); b.setText("ON"); b.setTextColor(0xff2d9ede); Intent k = new Intent(getApplicationContext(), serve.class); startService(k); } } if(resultCode == RESULT_FIRST_USER){ Button b = (Button)findViewById(R.id.button1); b.setText("ON"); b.setTextColor(0xff2d9ede); Intent k = new Intent(getApplicationContext(), serve.class); startService(k); } if(resultCode == RESULT_OK){ Button b = (Button)findViewById(R.id.button1); b.setText("ON"); b.setTextColor(0xff2d9ede); Intent k = new Intent(getApplicationContext(), serve.class); startService(k); } } } </code></pre> <p>but this also didn't work ..The same happened (didn't go back to my app).. any Ideas ?? ... thanks in advance</p> <p>here is the code of the whole activity:</p> <pre><code>public class Layout2Activity extends Activity { static String username4 ; private static final int DIALOG_ALERT = 10; private static final int DIALOG_ALERT2 = 8; public boolean onKeyDown(int keyCode, KeyEvent event) { if (event.getAction() == KeyEvent.ACTION_DOWN) { switch (keyCode) { case KeyEvent.KEYCODE_BACK: showDialog(DIALOG_ALERT); return true; } } return super.onKeyDown(keyCode, event); } boolean isGPSEnabled = false; boolean isNetworkEnabled = false; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.menu); ActionBar actionBar = getActionBar(); actionBar.setDisplayHomeAsUpEnabled(false); SharedPreferences name = getSharedPreferences("user", MODE_PRIVATE); username4 = name.getString("name"+Passwardentry.usernomain,"Admin"); SharedPreferences p = getSharedPreferences("user", MODE_PRIVATE); String number = p.getString("mob"+Passwardentry.usernomain, "please assign no."); SharedPreferences last = getSharedPreferences("user", MODE_PRIVATE); SharedPreferences.Editor edit = last.edit(); edit.putString("last number", number); edit.commit(); TextView k = (TextView) findViewById(R.id.textView2); k.setText(username4); TextView t = (TextView) findViewById(R.id.textView4); t.setText(number); if (serve.isStarted) { Button b = (Button)findViewById(R.id.button1); b.setText("ON"); b.setTextColor(0xff2d9ede); //TextView n = (TextView) findViewById(R.id.textView5); // n.setTextColor(0x7fff00); leh el 2alwan mesh zahra ?? //n.setText(" On "); } else { //TextView n = (TextView) findViewById(R.id.textView5); // n.setTextColor(0xff0000); //n.setText(" Off "); Button b = (Button)findViewById(R.id.button1); b.setText("OFF"); b.setTextColor(Color.rgb( 139,137,137 )); } } public void userchange(View v) { Intent i = new Intent(getApplicationContext(), setuserc.class); startActivity(i); } public void servicebutton(View V) { if (serve.isStarted) { //TextView n = (TextView) findViewById(R.id.textView5); // n.setTextColor(0xff0000); //n.setText(" Off "); Button b = (Button)findViewById(R.id.button1); b.setText("OFF"); b.setTextColor(Color.rgb( 139,137,137 )); Intent i = new Intent(getApplicationContext(), serve.class); stopService(i); } else { //TextView n = (TextView) findViewById(R.id.textView5); // n.setTextColor(0x7fff00); //n.setText(" On "); LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE); // getting GPS status isGPSEnabled = locationManager .isProviderEnabled(LocationManager.GPS_PROVIDER); // getting network status isNetworkEnabled = locationManager .isProviderEnabled(LocationManager.NETWORK_PROVIDER); if(isGPSEnabled &amp;&amp; isNetworkEnabled){ Button b = (Button)findViewById(R.id.button1); b.setText("ON"); b.setTextColor(0xff2d9ede); Intent k = new Intent(getApplicationContext(), serve.class); startService(k);} else { showDialog(DIALOG_ALERT2); } } } public void readingsbutt(View V) { Intent i = new Intent(getApplicationContext(), Readings.class); startActivity(i); } public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.activity_intro, menu); super.onCreateOptionsMenu(menu); // int group1 = 1; // MenuItem infoBtn = menu.add(group1,1,1,"About"); // MenuItem mn = menu.add(group1, 2, 2, "arm"); // mn.setIcon(R.drawable.set); // infoBtn.setIcon(R.drawable.set); //int group2=2; // MenuItem appSettings = menu.add(group2,3,2,"Application Settings"); // appSettings.setIcon(R.drawable.set); return true; } public boolean onOptionsItemSelected(MenuItem item) { if (item.getItemId() == R.id.menu_settings) { Intent i = new Intent(getApplicationContext(), settings.class); startActivity(i); overridePendingTransition(R.anim.slide_in, R.anim.slide_out); } if (item.getItemId() == R.id.help) { Intent i = new Intent(getApplicationContext(), help.class); startActivity(i); } if (item.getItemId() == R.id.about) { Intent i = new Intent(getApplicationContext(), Info.class); startActivity(i); } //switch(item.getItemId()) { // case 1: // break; // case 2: // break; // } return true; } @Override protected Dialog onCreateDialog(int id) { switch (id) { case DIALOG_ALERT: // Create out AlterDialog Builder builder = new AlertDialog.Builder(this); builder.setMessage("Are you sure you want to Quit ?"); builder.setCancelable(true); builder.setPositiveButton("NO", new OkOnClickListener()); builder.setNegativeButton("Yes", new CancelOnClickListener()); AlertDialog dialog = builder.create(); dialog.show(); case DIALOG_ALERT2: // Create out AlterDialog Builder builder2 = new AlertDialog.Builder(this); builder2.setMessage("No location service available please activate network and satellite GPS "); builder2.setCancelable(true); builder2.setPositiveButton("Cancel", new OkOnClickListener2()); builder2.setNegativeButton("Settings", new CancelOnClickListener2()); AlertDialog dialog2 = builder2.create(); dialog2.show(); } return super.onCreateDialog(id); } private final class CancelOnClickListener implements DialogInterface.OnClickListener { public void onClick(DialogInterface dialog, int which) { setResult(0); finish(); System.exit(0);// /el 2aaady }} private final class OkOnClickListener implements DialogInterface.OnClickListener { public void onClick(DialogInterface dialog, int which) { } } private final class CancelOnClickListener2 implements DialogInterface.OnClickListener { public void onClick(DialogInterface dialog, int which) { Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS); startActivityForResult(intent, 0); }} private final class OkOnClickListener2 implements DialogInterface.OnClickListener { public void onClick(DialogInterface dialog, int which) { } } public void onActivityResult(int requestCode, int resultCode, Intent x){ if(requestCode == 0){ if(resultCode == RESULT_CANCELED){ Button b = (Button)findViewById(R.id.button1); b.setText("ON"); b.setTextColor(0xff2d9ede); Intent k = new Intent(getApplicationContext(), serve.class); startService(k); } } if(resultCode == RESULT_FIRST_USER){ Button b = (Button)findViewById(R.id.button1); b.setText("ON"); b.setTextColor(0xff2d9ede); Intent k = new Intent(getApplicationContext(), serve.class); startService(k); } if(resultCode == RESULT_OK){ Button b = (Button)findViewById(R.id.button1); b.setText("ON"); b.setTextColor(0xff2d9ede); Intent k = new Intent(getApplicationContext(), serve.class); startService(k); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload