Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8132623
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T09:23:31+00:00 2026-06-06T09:23:31+00:00

I am using AsyncTask in my App. How can i make my Task resume

  • 0

I am using AsyncTask in my App.

How can i make my Task resume in working even if orientation change.

This the task :-

package com.android.grad;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.net.Uri;
import android.os.AsyncTask;
import android.provider.MediaStore;

public class LoginTask extends AsyncTask<Void, Void, Boolean> {

    private Activity activity;
    private ProgressDialog pd;
    private Uri fileUri;
    private final int CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE = 100;

    public LoginTask(Activity activity, Uri fileUri) {
        this.activity = activity;
        this.fileUri = fileUri;
    }

    @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(1000);
        } catch (InterruptedException e) {
        }
        return true;
    }

    @Override
    protected void onPostExecute(Boolean result) {
        pd.dismiss();
        pd = null;

        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri);
        activity.startActivityForResult(intent,
                CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);
    }
}    

public class LoginActivity extends Activity {

private final int MEDIA_TYPE_IMAGE = 1;
private CheckBox rememberMe;
private EditText userName, passWord;
private Button loginBtn;
private final int CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE = 100;
private String path;
private Uri fileUri;

private OnClickListener loginOnClick = new OnClickListener() {
    public void onClick(View v) {
        new LoginTask(LoginActivity.this, fileUri).execute();
    }
};

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.login);

    fileUri = getOutputMediaFileUri(MEDIA_TYPE_IMAGE);
    path = fileUri.getPath();

    loginBtn = (Button) findViewById(R.id.signInBtn);
    loginBtn.setOnClickListener(loginOnClick);

    rememberMe = (CheckBox) findViewById(R.id.keepMe);

    userName = (EditText) findViewById(R.id.userNameID);
    passWord = (EditText) findViewById(R.id.passwordID);
}

@Override
protected void onResume() {
    super.onResume();
    SharedPreferences sp = getSharedPreferences("user", MODE_PRIVATE);
    try {
        userName.setText(sp.getString("username", ""));
        passWord.setText(sp.getString("password", ""));
        rememberMe.setChecked(sp.getBoolean("rememberMe", false));
    } catch (ClassCastException ex) {
    }
}

@Override
protected void onPause() {
    super.onPause();

    SharedPreferences sp = getSharedPreferences("user", MODE_PRIVATE);
    Editor editor = sp.edit();
    if (rememberMe.isChecked()) {
        editor.putString("username", userName.getText().toString());
        editor.putString("password", passWord.getText().toString());
    } else {
        editor.putString("username", "");
        editor.putString("password", "");
    }
    editor.putBoolean("rememberMe", rememberMe.isChecked());
    editor.commit();
}

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE) {
        if (resultCode == RESULT_OK) {

            Intent intent = new Intent(LoginActivity.this,
                    PreviewActivity.class);
            intent.putExtra("path", path);
            startActivity(intent);

        } else if (resultCode == RESULT_CANCELED) {
            // User cancelled the image capture
            Toast.makeText(getApplicationContext(),
                    "User cancelled the image capture", Toast.LENGTH_LONG)
                    .show();
        } else {
            // Image capture failed, advise user
        }
    }
}

How can i handle that in LoginActivity.
How can i save the state of progressBar to continue after screen orientation.

Manifest file

    <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.Camera"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="15" />

    <uses-configuration android:configChanges="orientation|keyboardHidden|navigation"/>    
    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

    <uses-feature android:name="android.hardware.camera" />
    <uses-feature android:name="android.hardware.camera.autofocus" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" android:debuggable="true">
        <activity
            android:name="com.android.grad.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name="com.android.grad.CameraActivity" >
        </activity>
        <activity
            android:name="com.android.grad.LoginActivity"
            android:configChanges="orientation|keyboardHidden" >
        </activity>
        <activity
            android:name="com.android.grad.PreviewActivity"
             >
        </activity>
        <activity android:name="com.android.grad.BuiltInCamera"></activity>
    </application>

</manifest>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T09:23:31+00:00Added an answer on June 6, 2026 at 9:23 am

    Please put

    android:configChanges=”orientation|keyboardHidden”

    in the activity which ever you want to provide support for orientation changes.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my app I have a background task (using AsyncTask) that downloads stuff from
I am using this code (inside an AsyncTask) to download files: URL u =
In my app i have a processDialog (using AsyncTask) and at doInbackground it fetches
My app downloads some assets from my server using an AsyncTask and I put
I'm making an app that records uncompressed (wav format) audio. I'm using this class
I'm working on a Smartphone / Tablet app, using only one APK, and loading
I have been using Asynctask most of time, but in the current app the
I press login button to login into my app and I'm using asyncTask for
I am trying to run to Android code using an AsyncTask . However it
I am using AsyncTask to set my items and stuff, in the postExecute i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.