English 中文(简体)
使用 AsyncTask 启动活动
原标题:Using AsyncTask to start activity

几分钟后又发起新的活动。

很不幸,在任务完成之前就开始了?

package com.android.grad;

import android.app.Activity;

import android.app.ProgressDialog;

import android.os.AsyncTask;

import android.widget.Toast;

public class LoginTask extends AsyncTask<Void, Void, Boolean> {
private Activity activity;
private ProgressDialog pd;

public LoginTask(Activity activity) {
    this.activity = activity;
时 时

@Override
protected void onPreExecute() {
    pd = ProgressDialog.show(activity, "Signing in",
            "Please wait while we are signing you in..");
时 时

@Override
protected Boolean doInBackground(Void... arg0) {
    try {
        Thread.sleep(10000000);
    时 时 catch (InterruptedException e) {
    时 时
    pd.dismiss();
    return true;
时 时

@Override
protected void onPostExecute(Boolean result) {
    Toast.makeText(activity, Boolean.toString(result), Toast.LENGTH_LONG).show();
时 时

时 时

并执行按键点击收听器的任务 :S

private OnClickListener loginOnClick = new OnClickListener() {

        public void onClick(View v) {
            new LoginTask(LoginActivity.this).execute();
            startActivity(new Intent(LoginActivity.this, BuiltInCamera.class));
        时 时
    时 时;

有办法从我的亚亚亚星表开始活动吗?

最佳回答

是的, 您可以从 AsyncTassk 子类开始活动 。 见下文 :

@Override
protected void onPostExecute(Boolean result) {
    Toast.makeText(activity, Boolean.toString(result), Toast.LENGTH_LONG).show();

    activity.startActivity(new Intent(activity, BuiltInCamera.class));
}

更改此更改后, 请确定您确实从 < code> OnClickLististleer 中删除 < stractactivity

问题回答

调用 start Acticity( 显示吐司消息后, 调用 < code> start Acticity ( new intent( login Actical. this, builtInCamera. class. class) 的 ; < code> on PostExecute () 的 < /code > 。

这样, 您的 < code> AsyncTask 结束后将调用新活动 。

您也可以使用

    Intent intent = new Intent(activity, PageViewActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
    activity.getApplicationContext().startActivity(intent);

AsyncTask 中调用 AsyncTask 方法 启动活动





相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签