Android random time delayed user abortable infinite loop

by Ronoli » Wed, 22 Dec 2010 06:47:42 GMT


Sponsored Links
 Hello, can anyone show me the proper way to resolve my problem?,
I'm trying to to play a sound repeatedly but I need it to play with a
random delay.
When I grab a random number and start looping my sound, sure it plays
some random time later and continues to do so. But I want to use a new
random number for the delay between each loop.

Pseudo code:
1) Grab random number. (java.util.random).
2) Change that random number to represent seconds.
3) Pause or wait for that random amount of seconds.
4) Play sound from soundpool. (just mimic this as my soundpool is
working fine)
5) Grab new random number and repeat steps 3 through 5 and repeat this
process until the user cancels with a button.
6) Enable the user to cancel this loop at any time.

I would really appreciate a little help if someone can find the
time....
Thank you in advance,
javat...@gmail.com

-- 



Re: Android random time delayed user abortable infinite loop

by TreKing » Wed, 22 Dec 2010 12:53:32 GMT


 




I do think I understand what your actual problem is. What, specifically, are
you having trouble with given your pseudo-code description?

-------------------------------------------------------------------------------------------------
TreKing < http://sites.google.com/site/rezmobileapps/treking> ; - Chicago
transit tracking app for Android-powered devices

-- 


Sponsored Links


Re: Android random time delayed user abortable infinite loop

by Ron Richmond » Tue, 28 Dec 2010 01:51:09 GMT


 Hello and thanks for the reply,
It's really the user abortable loop that I'm having trouble with now.
Since first posting my problem, I have been researching code snippets and
have zeroed in on this one:

import java.util.Timer;
import java.util.TimerTask;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

public class DelayTimer extends Activity {

    TextView mTextField;
    long elapsed;
    final static long INTERVAL=1000;
    final static long TIMEOUT=5000;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        mTextField=(TextView)findViewById(R.id.textview1);

        TimerTask task=new TimerTask(){
            @Override
            public void run() {
                elapsed += INTERVAL;
                if(elapsed >= TIMEOUT){
                    this.cancel();
                    displayText("finished");
                    return;
                }
                //if(some other conditions)
                //   this.cancel();
                displayText("seconds elapsed: " + elapsed / 1000);
            }
        };
        Timer timer = new Timer();
        timer.scheduleAtFixedRate(task, INTERVAL, INTERVAL);
    }

    private void displayText(final String text){
        this.runOnUiThread(new Runnable(){
            @Override
            public void run() {
                mTextField.setText(text);
            }});
    }
}

I think I should be able to replace the static long INTERVAL with a call to
java.util.random
in a way that would work for me. However, I can't even get this example to
finish/abort/end properly.
After running this example, I have to go to "Manage Apps" and click "Force
Close" to kill it.
I'm not really sure if this is example is the best way to handle it either
but it is where I seem to be
zeroing in on. Any suggestions?
Thank you sooo much for your help,
Ron






-- 



Re: Android random time delayed user abortable infinite loop

by Bret Foreman » Tue, 28 Dec 2010 02:02:53 GMT


 Well first, you need a call to finish() somewhere in order to exit the
Activty.

-- 



Re: Re: Android random time delayed user abortable infinite loop

by Ron Richmond » Tue, 28 Dec 2010 02:09:50 GMT


 Thank You,
I will be working on my problem today as I was pulled away from it for a few
days (Holidays!)
Thanks again, I really appreciate any and all help!!
Ron





-- 



Other Threads

1. 2 Activities in MAIN LAUNCHER but...

Hi, I created an application with 2 Activities as set in the Manifest
MAIN and LAUNCHER because I want to have 2 separate icons that launch
the Activity in the menu of applications.

It happens to me that when I download the program from the market and
it's installed, when I click on the notification icon it ask me what
program to associate with my application, why?

How do I set the default Activity from the notification to start
installation?

If you want test it is SysInfo Widget.

Thanks to all
Bye

-- 

2. startactivity vs launch from home screen - for adobe AIR app

Hi,

I downloaded this java application from net.
Link : 
http://rosarioconti.wordpress.com/2010/10/03/extending-your-android-air-application-using-java/

Basically this application uses
dexLoader.loadClass("com.adobe.air.AndroidActivityWrapper") to create
class instance and then call "OnCreate()" method of Adobe Air class
with swf file name as an argument. And so air runtime is launched and
SWF file is run.

This activity is working perfectly fine.

Now when I try to launch same activity via startactivity(), activity
is launched successfully. All function calls are done successfully.
But Air application is not launched. I can say, Java part is loaded
successfully because I can see buttons which I put in java app layout.

I am not getting the reason, why application launches AIR module and
SWF while invoking directly but not when calling from another
activity.

I tried several permutations like : multiprocess flag true; specify
process name; specify task affinity etc.; but no luck!!!

So I want to know:

1. What is difference between startactivity()  and clicking on
activity from home screen?
2. How to invoke Air Application via StartActivity?

Thanks
Niket

-- 

3. Getting current time OR GMT offset for any location.

4. How to Upgrade Android Platform - opencv issue

5. emulator.exe has encountered a problem and needs to close. We are sorry for the inconvenience.emulator.exe has encountered a problem and needs to close. We are sorry for the inc

6. Sending mail broadcastreceiver

7. Array list to spinner OR json Array to java Array ?