Sunday, March 2, 2014

Jump in the middle with two activity progress bar. android


The first two activity button click event of a query is executed, the larger amount of data, so the jump to wait a long time, would like to use solid progress bar shows the program is running ... how?
<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:
Click the button show a ProgressDialog, then open a thread to execute the query, the query is completed by Handler closed ProgressDialog, start the next activity.
Reply:
The reply was deleted at the moderator 2011-03-08 17:19:50

Reply:
Should be able to read it

 
package com.zyq.main;

import java.util.ArrayList;

import android.app.Activity;
import android.app.Dialog;
import android.app.ListActivity;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.Toast;
public class ListProgressDemo extends ListActivity {
private ArrayAdapter adapter;
private ArrayList data;

private static final int PROGRESS_DIALOG = 1;
private static final int STATE_FINISH = 1;
private static final int STATE_ERROR = -1;

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

((Button) findViewById (R.id.load_Handler)). SetOnClickListener (new View.OnClickListener () {

@ Override
public void onClick (View view) {
data = null;
data = new ArrayList ();

adapter = null;

showDialog (PROGRESS_DIALOG);
new ProgressThread (handler, data) start ();.
}
});
}

@ Override
protected Dialog onCreateDialog (int id) {
switch (id) {
case PROGRESS_DIALOG:
return ProgressDialog.show (this, "",
". Loading Please wait ...", true);

default: return null;
}
}

private class ProgressThread extends Thread {

private Handler handler;
private ArrayList data;

public ProgressThread (Handler handler, ArrayList data) {
this.handler = handler;
this.data = data;
}

@ Override
public void run () {
for (int i = 0; i <8; i + +) {
data.add ("ListItem"); / / background data processing
try {
Thread.sleep (100);
} Catch (InterruptedException e) {

Message msg = handler.obtainMessage ();
Bundle b = new Bundle ();
b.putInt ("state", STATE_ERROR);
msg.setData (b);
handler.sendMessage (msg);

}
}
Message msg = handler.obtainMessage ();
Bundle b = new Bundle ();
b.putInt ("state", STATE_FINISH);
msg.setData (b);
handler.sendMessage (msg);
}

}

/ / Here even need to set Looper, Handler default because it uses the current thread's Looper
private final Handler handler = new Handler (Looper.getMainLooper ()) {

public void handleMessage (Message msg) {/ / handle Message, update ListView
int state = msg.getData () getInt ("state");.
switch (state) {
case STATE_FINISH:
dismissDialog (PROGRESS_DIALOG);
Toast.makeText (getApplicationContext (),
"Loading is complete!",
Toast.LENGTH_LONG)
. Show ();

adapter = new ArrayAdapter (getApplicationContext (),
android.R.layout.simple_list_item_1,
data);

setListAdapter (adapter);

break;

case STATE_ERROR:
dismissDialog (PROGRESS_DIALOG);
Toast.makeText (getApplicationContext (),
"Processing error has occurred!",
Toast.LENGTH_LONG)
. Show ();

adapter = new ArrayAdapter (getApplicationContext (),
android.R.layout.simple_list_item_1,
data);

setListAdapter (adapter);

break;

default:

}
}
};
}

Reply:
The reply was deleted on 2011-03-09 08:43:58 moderator

Reply:
reference to the third floor hosterzhu reply:
should be able to read it

Java code

package com.zyq.main;

import java.util.ArrayList;

import android.app.Activity;
import android.app.Dialog;
import android.app.ListActivity;
import android.app.ProgressDialog;
......

If there is no activity to jump it.
Reply:
cited a floor madsky007 reply:
after clicking the button show a ProgressDialog, then open a thread to execute the query, the query is completed by Handler closed ProgressDialog, next start an activity.
query in the latter activity. Before an activity is only responsible for the transfer parameters.

Reply:
Landlord, 3rd Floor, key code has been written. activity jump plus wants.
Reply:
Top 3 #,

Looks like there is on the fourth floor, oh m
Reply:
reference to the 8th floor sky123123 reply:
top 3 #,

Looks like there is on the fourth floor Oh meters

Ah, yes, oh .... # 3 accounted for two-layer?
Reply:
Paste the long code will occupy two? BUG?
Reply:
reference to the 10th floor h_jian2009 reply:
paste long code will occupy two? BUG?


Not put! Should be their irrigation, irrigation technology area are not allowed.
Reply:
The progress bar is not to be a problem, right?

Maybe I was not very good, I think this problem is difficult.
Jump to another activity because of this process, would like to start another activity, it is also routed to the back of the queue, so only the first pop-up process before the jump box, then the first activity can access the process box, the first two activity you want to access difficult, because not start up ah.
I do not know the landlord called slow, slow data query, or is it to start the second activity is slow, if the former is slow, that is quite a process you can use frames to display process.

It was made out of it? Look at the code.
Reply:
The reply was deleted at the moderator 2011-04-07 10:06:10

Reply:
package CityLife.View;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.Bitmap.Config;
import android.graphics.Paint.Style;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
public class StartView extends Activity
{
/ /
Paint paint = null;
Bitmap mSCBitmap = null;
Canvas mCanvas = null;
/ /
int a, b;
int startDrawBgX, startDrawBgY;
int startProgressX, startProgressY;
int startRectX, startRectY;
int rectW, rectH;
Bitmap bmpStartBg;
Bitmap bmpProgressBar;
Bitmap bmpStartBgL;
Bitmap bmpProgressBarL;
Boolean runA = true;
/ /
private MyView myView;
private Handler mHandler;
/ ** Called when the activity is first created. * /
@ Override
public void onCreate (Bundle savedInstanceState)
{
/ / Set fullscreen
this.requestWindowFeature (Window.FEATURE_NO_TITLE);
this.getWindow (). setFlags (WindowManager.LayoutParams.TYPE_STATUS_BAR,
WindowManager.LayoutParams.TYPE_STATUS_BAR);
/ /
super.onCreate (savedInstanceState);
setContentView (R.layout.main);
/ /
bmpStartBg = BitmapFactory.decodeResource (getResources (), R.drawable.startbg);
bmpProgressBar = BitmapFactory.decodeResource (getResources (), R.drawable.progressbg);
/ /
int w = bmpStartBg.getWidth () * 2;
int h = bmpStartBg.getWidth ();
int width = bmpStartBg.getWidth ();
int height = bmpStartBg.getHeight ();
int newWidth = w;
int newHeight = h;
float scaleWidth = ((float) newWidth) / width;
float scaleHeight = ((float) newHeight) / height;
a = (int) scaleWidth;
b = (int) scaleHeight;
/ /
Matrix matrix = new Matrix ();
matrix.postScale (a, b);
/ /
bmpStartBgL = Bitmap.createBitmap (bmpStartBg, 0, 0, bmpStartBg.getWidth (), bmpStartBg.getHeight (), matrix, true);
bmpProgressBarL = Bitmap.createBitmap (bmpProgressBar, 0, 0, bmpProgressBar.getWidth (), bmpProgressBar.getHeight (), matrix, true);
/ /
startDrawBgY = (this.getWindowManager () getDefaultDisplay () getHeight () - bmpStartBgL.getHeight ()..) / 2 - 40;
startDrawBgX = (this.getWindowManager () getDefaultDisplay () getWidth () - bmpStartBgL.getWidth ()..) / 2;
/ /
startProgressY = (this.getWindowManager () getDefaultDisplay () getHeight () - bmpProgressBarL.getHeight ()..) / 2 - 15;
startProgressX = (this.getWindowManager () getDefaultDisplay () getWidth () - bmpProgressBarL.getWidth ()..) / 2;
/ /
startRectX = startProgressX;
startRectY = startProgressY;
rectW = startProgressX + bmpProgressBarL.getWidth ();
rectH = startProgressY + bmpProgressBarL.getHeight ();
/ /
myView = new MyView (this);
setContentView (myView);
/ /
mSCBitmap = Bitmap.createBitmap (320, 480, Config.ARGB_8888);
mCanvas = new Canvas ();
mCanvas.setBitmap (mSCBitmap);
/ /
mHandler = new Handler ();
mHandler.post (update);
}
private Runnable update = new Runnable ()
{
public void run ()
{
myView.update ();
mHandler.postDelayed (update, 100);
}
};
public class MyView extends View
{
public MyView (Context context)
{
super (context);
}
public void update ()
{
postInvalidate ();
}
protected void onDraw (Canvas canvas)
{
/ / Super.onDraw (canvas);
if (startRectX {
startRectX = startRectX + 2;
/ / First define a paint
paint = new Paint ();
/ / Set the style - filled
paint.setStyle (Style.FILL);
paint.setColor (UsedColor.startBgColor);
/ / Draw a rectangle
mCanvas.drawRect (new Rect (0, 0, getWidth (), getHeight ()), paint);
/ / Output background image
paint.setColor (UsedColor.progressBgColor);
mCanvas.drawBitmap (bmpStartBgL, startDrawBgX, startDrawBgY, paint);
mCanvas.drawBitmap (bmpProgressBarL, startProgressX, startProgressY, paint);
mCanvas.drawRect (new Rect (startRectX, startRectY, rectW, rectH), paint);
canvas.drawBitmap (mSCBitmap, 0, 0, paint);
}
else
{
if (runA)
{
finish ();
/ / Create an Intent object
Intent intent = new Intent ();
intent.putExtra ("textIntent", "");
intent.setClass (StartView.this, MainView.class);
StartView.this.startActivity (intent);
runA = false;
}
}
}
}
}

This is what I do a project that started at the beginning of a login screen activity and then enter the main interface.
Reply:
All code in here?

You're just like the process of giving the user a visual experience, ah, take the process of time, did not do anything, but did not like the landlord said, to start another activity, you are in the process of finish when we come start another activity of.

This process is more like your article a delay, rather than on behalf of a particular job progress.
Reply:
Really does not do the deal for the problem, if it is slow page jump, doing so is no effect.
Reply:
Comments do not know if I can. . Brother came just recently made a similar function, this paper presents a vision:
Jump to ActivityB
from ActivityA1, your next Activity thing is not loaded more? Do not run after the first B, you first in A, on the first point of the jump button to start loading, by the way began to draw a progress bar
2, until the load is over, the results are passed directly to the B (this should be a little faster)

No comments:

Post a Comment