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 8189263
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T03:13:07+00:00 2026-06-07T03:13:07+00:00

I have a problem with my code: I am working on an app that

  • 0

I have a problem with my code:

I am working on an app that requires you to log in. The app consists of a loading screen and then a tabView with 4 tabs. The last tab is an activity that wil let you login. I have set up EditText Views here and a Login button.

The login activity is done so far here’s the code:

package com.appsoweb.kvodeventer;

import org.json.JSONObject;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

public class KVOMeldingen extends Activity {

       public static final JSONObject jsonResult = null;
       Button bLogin, bCreateAccount, bResetPassword;
       EditText etUsername, etPassword;
       static String Username;
       static String Password;

       public void onCreate(Bundle savedInstanceState) {
             super.onCreate(savedInstanceState);
             setContentView(R.layout.meldingen);
             final EditText etUsername = (EditText) findViewById(R.id.etUsername);
             final EditText etPassword = (EditText) findViewById(R.id.etPassword);
             Button bLogin = (Button) findViewById(R.id.bLogin);
             Button bCreateAccount = (Button) findViewById(R.id.bCreateAccount);
             Button bResetPassword = (Button) findViewById(R.id.bResetPassword);

             bLogin.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                           if (etUsername.length() <= 0) {
                                  etUsername.setError("Veld mag niet leeg zijn");
                           } else if (etPassword.length() <= 0) {
                                  etPassword.setError("Veld mag niet leeg zijn");
                           } else {
                                  Username = etUsername.getText().toString();
                                  Password = etPassword.getText().toString();
                           }
                           LoginTask NDLT = new LoginTask();
                           NDLT.execute();
                    }
             });

             bCreateAccount.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View arg0) {
                           // Doe iets hier.......

                    }

             });

             bResetPassword.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                           // Doe iets hier........

                    }

             });

       }

       public static String getUsername() {
             return Username;
       }

       public static String getPassword() {
             return Password;
       }

       class LoginTask extends AsyncTask<Void, Void, JSONObject> {
             ProgressDialog waitingDialog;

             @Override
             protected void onPreExecute() {
                    waitingDialog = new ProgressDialog(KVOMeldingen.this);
                    waitingDialog.setMessage("Laden...");
                    waitingDialog.show();
                    super.onPreExecute();
             }

             @Override
             protected JSONObject doInBackground(Void... params) {

                    JSONObject json = JsonFunctionLogin
                                  .getJsonLoginResult("http://api.crossalertdeventer.nl/login.json");
                    return json;

             }

             @Override
             protected void onPostExecute(JSONObject json) {
                    super.onPostExecute(json);
                    if (waitingDialog.isShowing()) {
                           waitingDialog.dismiss();
                           Log.d("iets gebeurt", "gedaan");
                    }
                    try {

                           String LoginResult = json.getString("login");
                           String UserIdResult = json.getString("user_id");
                           Log.d("LoginResult", LoginResult);
                           Log.d("LoginUserId", UserIdResult);
                           json = null;
                           if (LoginResult == "succes"){
                                  // Open activity for listview.
                           } else {
                                  // Don't show items and give error message.
                           }


                    } catch (Exception e) {
                           Log.e("KVOMeldingen", "error" + e.getMessage());

                    }

             }
       }


}

You can see that the authentication happens in the background.

Now you see the If statement block on the postExecute method: I want to open an activity if the user is succesfully logged in, that loads json from the web and puts it in a list Item.

Now i don’t know how to do that. Because if I use an intent, the new listActivity is opened but not within the TabView of my Starting Activity. How can I do this?

  • 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-07T03:13:10+00:00Added an answer on June 7, 2026 at 3:13 am

    I did something similar, so try this. Pass the activity to the AsyncTask class and save it like a member variable. In onPostExecute() method, call a method from your main activity to open a new activity or to show an error message. It worked for me!! 😉

    Some code:

    public LoginTask(Activity parentActivity) {
            mParentActivity = parentActivity;
        }
    
    @Override
    protected void onPostExecute(JSONObject json) {
        ...
        if (LoginResult == "succes"){
            mParentActivity.openNewActivity(json);
        } else {
            mParentActivity.showErrorMessage("ERROR");
        }
        ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is the problem I have an app that is working in every browser
I am currently working on Problem 62 I have tried the following code to
I have a code problem which stems from the fact that I am using
I'm working on a app that requires a DB and I'm getting some problems,
I have a very strange error happening in an App that has been working
For the past few weeks I have been working on an app that uses
I have this problem that My WPF App in its MainWindow: public partial class
I have problem with javascript code. I am using google maps and I am
I have problem with this code: file = tempfile.TemporaryFile(mode='wrb') file.write(base64.b64decode(data)) file.flush() os.fsync(file) # file.seek(0)
Hi i have problem with this code, i found it on the internet and

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.