[android-developers] Async Task, rotation and indeterminate progressbar in custom header.

2011-09-23 Thread Bluemercury
Hi! So i've been trying to get a solution for a very specific problem that 
involves using Async tasks and dealing with the rotation and also a custom 
header that contains a progressbar view(the small spinner one, including a 
text view saying "Loading..."). I've followed 
this
 example 
to deal with the async tasks and the rotation, but i still have the problem 
of the progressbar, if activity A launches a task and i imediately go to 
activitity B, the progress bar in activity B should still appear visibile 
even though the task was launched from activity A, how do i this without a 
static reference for the progressbar view?, the postexecute method of the 
async have to consider the possibility that the progressbar reference should 
now be in another activity, right?
Here's my code for my parent activity where subactivities extend from:

public abstract class ParentClass extends Activity{

protected static ProgressBar progressHeader = null;
protected static TextView progressLoading = null;;

protected static int progressBarstate=ProgressBar.GONE;
protected static int themeId;

private ProgressBarThread task=null;

//this method will get the id for the layout 
public abstract int getLayoutId();
//this method will launch respejcting oncreate logic for each activity 
public abstract void initActivity();
//thi smethod will return window header menu context text string
public abstract String getWindowTitle();
//this method is used to refresh contents for a screen
public abstract void updateResultsInUi();
//nethod for definined specific theme 
public abstract int getThemeId();


@Override
protected void onCreate(Bundle savedInstanceState) {


//set theme first for showing correct header
setTheme(getThemeId());

super.onCreate(savedInstanceState);

themeId=getThemeId();
//in case the screen will have a header
if(getThemeId()!=R.style.CustomThemeNoHeader){

requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);

setContentView(getLayoutId());

getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, 
R.layout.custom_window_title);

//set text header
((TextView)findViewById(R.id.header_title)).setText(getWindowTitle());

progressRefreshState(progressBarstate);

}else
{
setContentView(getLayoutId());
}

//execute subactivity logic
initActivity();

}

/**
 * check for loading/spinner icon in
 *  case there's a thread working in background
 */
@Override
public void onRestart () {
super.onRestart();
if(getThemeId()!=R.style.CustomThemeNoHeader){
//Toast.makeText(this, "visible(0): " + ProgressBar.VISIBLE+" : Current :" + 
getProgressBarstate(), Toast.LENGTH_LONG).show();
progressRefreshState(progressBarstate);

}
}


@Override
public Object onRetainNonConfigurationInstance() {
if(task!=null)
task.detach();

return(task);
}

/**
 * refresh static references for both progress 
 * info views and set visibility state
 */
private void progressRefreshState(int state) {

progressHeader  = (ProgressBar) findViewById(R.id.progresspinner);
progressLoading = (TextView) findViewById(R.id.progresstext); 

progressHeader .setVisibility(state);
progressLoading.setVisibility(state);
}

//todo change location for getting session
protected String getSession(){

LogInManager login=new LogInManager(ParentClass.this);
try {
boolean session=login.getNewSession(
QuadrosMobileApplicationContext.getInstance().getUser(),
QuadrosMobileApplicationContext.getInstance().getPass());

if(session)
return getString(R.string.login_sucessful);
else
return getString(R.string.login_failed);
} catch (RequestException e) {
return e.getMessage();
}
}

/**
 * do asynctask for background work
 */
public void doAsyncTask(){

task= (ProgressBarThread)getLastNonConfigurationInstance();

if(task==null){
task= new ProgressBarThread(this);
task.execute();
//add to the set of tasks
QuadrosMobileApplicationContext appliContext= 
(QuadrosMobileApplicationContext)getApplicationContext();
appliContext.getAsyncTasks().add(task);
}else{
task.attach(this);
}
}


static public class ProgressBarThread extends AsyncTask{
ParentClass activity=null;



public ProgressBarThread(ParentClass activity) {

attach(activity);
}

@Override
protected void onPreExecute() {
Logger.write("ProgressBarThread ", " AsyncTask pre execution ", 
Logger.INFO);

if(themeId!=R.style.CustomThemeNoHeader){
progressHeader.setVisibility(ProgressBar.VISIBLE);
progressLoading.setVisibility(ProgressBar.VISIBLE);
}
progressBarstate=ProgressBar.VISIBLE;
} 

@Override
protected Void doInBackground(Void... params) {
Logger.write("ProgressBarThread ", "initialized", Logger.INFO);
activity.updateResultsInUi();
Logger.write("ProgressBarThread ", "Finish", Logger.INFO);
return null;
}

@Override
protected void onPostExecute(Void result) {
Logger.write("ProgressBarThread ", " AsyncTask post execution ", 
Logger.INFO);

//remove this task from collection
QuadrosMobileApplicationContext

Re: [android-developers] Async Task

2011-07-02 Thread NaveenShrivastva
On Sat, Jul 2, 2011 at 3:20 PM, naveen kumar wrote:

> hi all,
>
> i have multiple long process for one activity, i want to many process
> with multiple thread in android.
>
> i want to use Async task please help me Async task Simultaneous handle
> multiple process or One activity is able to execute more than one
> async task or one Activity have only one async task
>
> Plz reply
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to android-developers@googlegroups.com
> To unsubscribe from this group, send email to
> android-developers+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en


i have handle that one


thanks all

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] Async Task

2011-07-02 Thread naveen kumar
hi all,

i have multiple long process for one activity, i want to many process
with multiple thread in android.

i want to use Async task please help me Async task Simultaneous handle
multiple process or One activity is able to execute more than one
async task or one Activity have only one async task

Plz reply

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


Re: [android-developers] Async Task or Spawn a Thread?

2011-05-07 Thread Ralph Bergmann
Am 07.05.11 17:53, schrieb Droid:
> Is one better than the other?

yes, but it depends on what you want to do

if you only want a background task you can do it a thread. if your task
acts with the ui you can do it with both but it is easier with the
asynctask (your thread vs. ui thread)

http://developer.android.com/resources/articles/painless-threading.html

-- 

Ralph Bergmann


www  http://www.dasralph.de/
mail ra...@dasralph.de
skypedasralph

facebook http://www.facebook.com/dasralph
xing http://www.xing.com/profile/Ralph_Bergmann3
linkedin http://www.linkedin.com/in/ralphbergmann
model kartei http://dasralph.model-kartei.de/

java user group  http://www.jug-bb.de | http://www.xing.com/net/jugbb
ios dev grouphttp://www.xing.com/net/iosberlin


pgp key id   30C4ECD8
pgp fingerprint  C6E4 3435 7CC8 5008 54EC 1C86 4176 7F75 30C4 ECD8

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


Re: [android-developers] Async Task or Spawn a Thread?

2011-05-07 Thread Kostya Vasilyev

07.05.2011 19:53, Droid пишет:

Seems I can use an async task OR roll my own thread to do a background
task.

Is one better than the other?


Not "better", mostly just plug into the rest of your code somewhat 
differently.


AsyncTask provides helpers methods, like onPreExecute, onProgressUpdate, 
which are conveniently called on the UI thread - Thread does not have those.


AsyncTask is not reusable, once it's executed, you will need to create a 
new one to execute a new work item. A thread can be written such that it 
gets work items from a queue, staying running.


AsyncTasks are executed in parallel prior to 3.0, and in 3.0 the default 
execution model is one task at a time (which can be changed). A thread 
is independent of other threads.


AsyncTask is faster and easier to get going, a Thread is a bit more work.

Neither AsyncTask nor Thread affect your process's lifetime.

--
Kostya Vasilyev -- http://kmansoft.wordpress.com

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Async Task or Spawn a Thread?

2011-05-07 Thread Droid
Seems I can use an async task OR roll my own thread to do a background
task.

Is one better than the other?

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Async Task Problem

2009-08-28 Thread glory

Hi All,

I am facing the problem of timelag between execution of onPreExecute()
and execution of doInbackground(String... params).On postExecute() of
the Asyc task I am starting a service.
First time when I am executing the async task it is working fine but
If I again executing the same Async task immediately then there is a
lag in execution of onPreExecute() and execution of doInbackground
(String... params).
I am doing nothing on onPreExecute() ,so doInbackground(String...
params) should execute immediately, is I am missing something

Thanks in Advance
Regards,
Glory
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~--~~~~--~~--~--~---