Hi
Below is the example for a Login Class that will solve your issue. You need
to understand it for implementing multithreading in your code. Reply back to
me [email protected] if you find any problem to understand it though
I 've put appropriate comments.
package com.torrins;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import android.widget.Toast;
public class Login extends Activity{
ProgressDialog dialog;
int increment;
ImageButton loginButton;
/******************* This is used to get the saved Prefrences
***************************/
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.login);
loginButton = (ImageButton)findViewById(R.id.ImageButton02);
loginButton.setOnClickListener(new OnClickListener() {
//@Override
public void onClick(View v) {
increment = 1;
dialog = new ProgressDialog(Login.this);
dialog.setCancelable(true);
dialog.setMessage("Login...");
// set the progress to be horizontal
dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
// reset the bar to the default value of 0
dialog.setProgress(0);
int maximum = 100;
// set the maximum value
dialog.setMax(maximum);
// display the progressbar
dialog.show();
/************************ Thread Creation
***********************/
// create a thread for updating the progress bar and logging
into the system
Thread background = new Thread (new Runnable() {
public void run() {
try {
Looper.prepare();
while (dialog.getProgress()<= dialog.getMax()) {
GenericXmlParser gp =new GenericXmlParser();
if(gp!=null){
/************************************ do
what you want to do with response xml *****************/
. . . . .. .
}
Thread.sleep(3000);
/**** active the update handler when the work
is done or the UI thread is needed to be given control for some time
**********/
progressHandler.sendMessage(progressHandler.obtainMessage());
}
} catch (java.lang.InterruptedException e) {
// if something fails do something smart
}
Looper.loop();
}
});
// start the background thread
background.start();
}
});
}
/****************** This is the place where you update your UIThread or the
thread that has called the other thread to process a task. *********/
Handler progressHandler = new Handler() {
public void handleMessage(Message msg) {
dialog.incrementProgressBy(increment);
if(dialog.getProgress()+200>=dialog.getMax())
dialog.dismiss();
finish();
// set login status here
//show the home screen
startActivity(new Intent(Login.this,torrins.class));
}
};
}
/// end of code
On Tue, Jul 20, 2010 at 8:26 PM, Matty <[email protected]> wrote:
> I'm not sure why you can't just use a thread (no handler)?
>
> If you do need a handler, you can just create a new runnable, and post
> it to the handler with something like:
>
> new Handler().post(new Runnable(){
> public void run(){
> image = new GLCamTest().extractimage(q);
> }
> });
>
>
>
>
> (Obviously, the code above isn't perfect, but hopefully it helps);
>
> On Jul 20, 9:28 am, Aidan C <[email protected]> wrote:
> > Hey guys,
> >
> > I've got 2 classes `GLLayer` and `GLCamTest`. I'm attempting to run a
> > method located in `GLCamTest`...
> >
> > public Bitmap extractimage(int pos){
> > LocationData tweets;
> > tweets = new LocationData(this);
> > SQLiteDatabase db = tweets.getWritableDatabase();
> > //select the data
> > String query = "SELECT * FROM tweets;";
> > Cursor mcursor = db.rawQuery(query, null);
> > //Move to Position specified.
> > mcursor.moveToPosition(pos);
> >
> > //get it as a ByteArray
> > byte[] imageByteArray=mcursor.getBlob(7);
> > //the cursor is not needed anymore
> > mcursor.close();
> >
> > //convert it back to an image
> > ByteArrayInputStream imageStream = new
> > ByteArrayInputStream(imageByteArray);
> > Bitmap theImage =
> BitmapFactory.decodeStream(imageStream);
> > return theImage;
> > }
> >
> > I'm looking to run in on a thread from `GLLayer` but from what I
> > understand I need a Handler..
> >
> > public void run() {
> > GLCamTest cam = new GLCamTest();
> > image = cam.extractimage(q);
> >
> > }
> >
> > I'm starting the Thread from within `public void onDrawFrame(GL10 gl)
> > {` my question is how would I implement said handler? I've readhttp://
> developer.android.com/reference/android/os/Handler.htmlbut I
> > still don't really understand how I'd implement it. could someone help
> > me out?
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]<android-developers%[email protected]>
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en
>
--
Thanks for Cooperating!
Anil Kukreti
Network transforms ideas to reality.
09312646623
Linked In : http://in.linkedin.com/in/anilkukreti
Blog : http://androidosbeginning.blogspot.com/
Skype Id : anil.kleward
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en