Results 1 to 2 of 2
  1. #1
    nour is offline Member
    Join Date
    Oct 2011
    Posts
    12
    Rep Power
    0

    Default how to make a program run in the background

    i am trying to make a program run in the background in android , i tried many service examples but it just got more complicate for me i am tring to run a simple app witch silents the phone when we turn it over (i know there is a Built in but that for sileting the phone when it is on it back we just put the phone on its "face" and it is in silent mode ) i am trying to do something similar like when we put the phone in our poket the magnetic filed shows the "y" is in "-num" (in num i mean number) but when we turn the phone upside down it becomes "+num" now i have the code that makes the phone silent and make sound here it is :
    Java Code:
    private SensorManager mSensorManager;
    private Sensor mSensor;
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    
        mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
        mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD);
    }
    
    @Override
    public void onAccuracyChanged(Sensor sensor, int accuracy) {
    
    
    }
     @Override
      protected void onResume() {
        super.onResume();
        mSensorManager.registerListener(this, mSensor, SensorManager.SENSOR_DELAY_NORMAL);
      }
    
      @Override
      protected void onPause() {
        super.onPause();
        mSensorManager.unregisterListener(this);
      }
    
    @Override
    public void onSensorChanged(SensorEvent event) {
    
        if (event.values[1] >= 29 )
        {
    
            ((AudioManager) getSystemService(AUDIO_SERVICE))
              .setRingerMode(AudioManager.RINGER_MODE_VIBRATE);
    
        }
        if (event.values[1] <= -29 )
            if (event.values[2] >= -15 && event.values[2] <= 2 )
        {
            ((AudioManager) getSystemService(AUDIO_SERVICE))
            .setRingerMode(AudioManager.RINGER_MODE_NORMAL);
        }
    
      }
    
    }
    but i dont know how to run it in the background so any body could help me with that thank's and have a nice day

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,458
    Rep Power
    20

    Default Re: how to make a program run in the background

    Quote Originally Posted by nour View Post
    i am trying to make a program run in the background in android
    Moved from New to Java.

    Please see this post.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. How to make Java program run in the background?
    By divs1210 in forum Advanced Java
    Replies: 7
    Last Post: 04-16-2011, 06:30 PM
  2. How to make transparent background of an applet
    By liketanglung in forum Java Applets
    Replies: 0
    Last Post: 03-21-2011, 09:07 AM
  3. How to make a background image
    By Purple Turtle in forum Java Software
    Replies: 2
    Last Post: 11-04-2010, 08:32 AM
  4. How do I make a timer run in the background?
    By caryr in forum Advanced Java
    Replies: 15
    Last Post: 09-04-2009, 03:34 AM
  5. How to make the JTextArea background invisible
    By bradder in forum AWT / Swing
    Replies: 1
    Last Post: 12-05-2007, 07:30 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •