Note that there are some explanatory texts on larger screens.

plurals
  1. POBring an activity to front?
    primarykey
    data
    text
    <p>I have two activities MainActivity and StopAlarm and on the shake of mobile i want to start the StopAlarm activity. But when my MainActivity is in minimized mode(Background) and i shake the mobile the StopAlarm activity is also started in minimized state. i want to start the StopAlarm activity in maximized start.(Activity should be on screen)</p> <pre><code> import android.app.Activity; import android.app.Application; import android.content.Context; import android.content.Intent; import android.hardware.Sensor; import android.hardware.SensorEvent; import android.hardware.SensorEventListener; import android.hardware.SensorManager; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.Spinner; import android.widget.Toast; public class MainActivity extends Activity { Intent in; private Button activate; private SensorManager mSensorManager; private float mAccel; private float mAccelCurrent; private float mAccelLast; Spinner sspinner, tspinner; String selectedTone, selectedTime; String ab; public int settime; public static int i; int act = 0; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); String[] sdata = { "Beep", "Police Siren", "Dog Bark" }; String[] tdata = { "05 sec", "10 sec", "15 sec" }; // final activate activteprocess = new activate(); sspinner = (Spinner) findViewById(R.id.soundspinner); sspinner.setAdapter(new ArrayAdapter&lt;String&gt;(this, R.layout.customspinner, R.id.textView1, sdata)); tspinner = (Spinner) findViewById(R.id.timespinner); tspinner.setAdapter(new ArrayAdapter&lt;String&gt;(this, R.layout.customspinner, R.id.textView1, tdata)); // /////////////////////////////////////////////////////////////////////////////////////// mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE); mSensorManager.registerListener(mSensorListener, mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), SensorManager.SENSOR_DELAY_NORMAL); mAccelCurrent = SensorManager.GRAVITY_EARTH; mAccelLast = SensorManager.GRAVITY_EARTH; activate = (Button) findViewById(R.id.button1); activate.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { selectedTime = tspinner.getSelectedItem().toString(); ab = selectedTime.substring(0, 2).trim(); settime = Integer.parseInt(ab); Toast.makeText(getApplicationContext(), "" + settime, 1500) .show(); selectedTone = sspinner.getSelectedItem().toString(); act = 1; // activteprocess.start(); } }); // ///////////////////////////////////////////////////////////////////////////////////////////////////////// } public final SensorEventListener mSensorListener = new SensorEventListener() { public void onSensorChanged(SensorEvent se) { float x = se.values[0]; float y = se.values[1]; float z = se.values[2]; mAccelLast = mAccelCurrent; mAccelCurrent = (float) Math.sqrt((double) (x * x + y * y + z * z)); float delta = mAccelCurrent - mAccelLast; if (delta &gt; 2 &amp;&amp; act == 1) { mAccel = mAccel * 0.9f + delta; if (i == 0) { i++; in = new Intent(getApplicationContext(), StopAlarm.class); in.putExtra("tone", selectedTone); // startActivity(in); //finish(); } } } public void onAccuracyChanged(Sensor sensor, int accuracy) { } }; </code></pre> <p>StopAlarm.java</p> <pre><code>public class StopAlarm extends Activity { String tonetoplay; MediaPlayer mp; int[] ab = { R.raw.dog, R.raw.police_siren, R.raw.thief_alarm }; Button stp; int done = 0; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.stopalarm); Intent abc = getIntent(); tonetoplay = abc.getStringExtra("tone"); startPlaying(); stp = (Button) findViewById(R.id.stopalaram); stp.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { mp.stop(); } }); } private void startPlaying() { if (tonetoplay.equals("Beep")) mp = MediaPlayer.create(getApplicationContext(), ab[2]); if (tonetoplay.equals("Police Siren")) mp = MediaPlayer.create(getApplicationContext(), ab[1]); if (tonetoplay.equals("Dog Bark")) mp = MediaPlayer.create(getApplicationContext(), ab[0]); mp.setLooping(true); mp.start(); } @Override protected void onResume() { Toast.makeText(getApplicationContext(), "" + tonetoplay,Toast.LENGTH_SHORT).show(); super.onResume(); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    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