Anand Krish
Anand Krish

Reputation: 479

Speedometer app - speed exceed alarm not working properly

App description -An Speedometer app, When exceeding a cutoff speed,an alarm triggers and the alarm should turned off when the speed comes under the cutoff speed.

Problem with the following code is alarm triggers on exceeding the cutoff speed, but the alarm is not turned off when the speed comes under the cutoff speed.

In the following code, on including "m1.stop()" even the alarm is not getting triggered that's why I made it as a comment so that the following code works well, but i need to turnoff the alarm when the speed comes under the cutoff speed. I am new to android programming. Please help me by pointing out my mistakes.

void update_speed( float x )
{

    speed = x;

    if ( x > speed_max )
        speed_max = x;

    if( x > cutoff)
    {

        m1.start();  //alarm triggers("m1" instance of mediaplayer)


    }
    else

      //m1.stop();/*on including this line even alarm is not getting triggered that's why i made it as comment*/


}

public void onLocationChanged( Location loc )
{
    num_updates++;

    if ( loc == null )
    {
        no_loc++;
        return;
    }

    if ( !loc.hasSpeed() )
    {
        no_speed++;
        return;
    }

    update_speed( loc.getSpeed() );
}

Upvotes: 1

Views: 197

Answers (0)

Related Questions