Global variable use in third activity
AnimationDrawable animation;
use in Frame by Frame animation
. i have use it this way ::
try {
ImageView img = (ImageView) findViewById(R.id.girl_anim);
animation = new AnimationDrawable();
new xyz()开发者_JAVA技巧.execute();
animation.setOneShot(false);
img.setBackgroundDrawable(animation);
img.post(new Starter());
} catch (Exception e) {
}
external class ::
private class xyz extends AsyncTask<Void, Void, Void> {
//private final ProgressDialog dialog = new ProgressDialog(tranning.this);
protected void onPreExecute() {
/*this.dialog.setMessage("Please Wait...");
this.dialog.show();
*/
}
@Override
protected Void doInBackground(Void... arg0) {
try {
for(int i = 1;i<54;i++)
{
Bitmap bitmap = BitmapFactory.decodeStream((InputStream) new URL(
"http://test/MRESC/images/test/girl/"+"girl000"+i+".png")
.getContent());
Drawable frame =new BitmapDrawable(bitmap);
animation.addFrame(frame, 50);
}
} catch (Exception e) {
}
return null;
}
protected void onPostExecute(final Void unused) {
//if (this.dialog.isShowing()) {
// this.dialog.dismiss();
//}
}
}
class Starter implements Runnable {
public void run() {
animation.start();
}
}
now this code used in third activity.but problem is that i want it at creation on first activity, so how can i do this?
You can either make the variable static, or you can just pass it as a parameter between the activities(putExtra), but because you use this in a async task, you might have to use a runnable:
handler.postDelayed(new Runnable() {
public void run() {
//do something with a variable from the activity
}
}, 100);
Also declare the handler in the activity:
private final Handler handler = new Handler();
精彩评论