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

  • Home
  • SEARCH
  • 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 7743201
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T09:28:17+00:00 2026-06-01T09:28:17+00:00

I have a method to insert data into server like this: public void doInsert(){

  • 0

I have a method to insert data into server like this:

public void doInsert(){

    try {
        // setiap parameter yang akan dikirim melalui http
        // harus encode agar
        // dapat terbaca dengan baik oleh server
        String no_imei = URLEncoder.encode(noImei.getText().toString(), "utf-8");
        String nik = URLEncoder.encode(user.getText().toString(), "utf-8");
        String pass = URLEncoder.encode(password.getText().toString(), "utf-8");
        url += "?no_imei=" + no_imei + "&&nik=" + nik + "&&password=" + pass;
        getRequest(url);
        } catch (UnsupportedEncodingException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

Another method that I have:

public void getRequest(String Url) {

    HttpClient client = new DefaultHttpClient();
    HttpGet request = new HttpGet(url);
    try {
        HttpResponse response = client.execute(request);
        Toast.makeText(this, "Tambah Data " + request(response) + " ",Toast.LENGTH_SHORT).show();
    } catch (Exception ex) {

        //Toast.makeText(this, "Tambah Data Gagal !", Toast.LENGTH_SHORT).show();
      }
}

And like this:

public static String request(HttpResponse response) {

    String result = "";
    try {
        InputStream in = response.getEntity().getContent();
        BufferedReader reader = new BufferedReader(
        new InputStreamReader(in));
        StringBuilder str = new StringBuilder();
        String line = null;
        while ((line = reader.readLine()) != null) {

            str.append(line + "\n");

        }
        in.close();
        result = str.toString();
        } catch (Exception ex) {
        result = "Error";
        }
        return result;

}

onClick method:

private View.OnClickListener onSave=new View.OnClickListener() 
{
    public void onClick(View v) 
    {
        //Dbhelper helper = new Dbhelper(UserForm.this);  
        Cursor c = helper.Login(almagId);

        if (noImei.getText().toString().equals("")||
            user.getText().toString().equals("")||
            password.getText().toString().equals("")
            ) {
            Toast.makeText(UserForm.this, "Data Harus di isi", Toast.LENGTH_LONG).show();

    }else if(c.moveToFirst()){
        if(noImei.getText().equals(c.getString(0))||
                user.getText().equals(c.getString(1))){
            Toast.makeText(UserForm.this, "Data Sudah ada", Toast.LENGTH_LONG).show();
            helper.close();
        }
    }else
    {
        doInsert(); 
        helper.insertUser(noImei.getText().toString(),user.getText().toString(),password.getText().toString());
            //Toast.makeText(UserForm.this, "Data Berhasil disimpan", Toast.LENGTH_LONG).show();

    }
        startActivity(new Intent(UserForm.this,MenuUtama.class));
        user.setText("");
        password.setText("");
         return;
    }
};

In the onClick method when response from server SUCCESS I want to do some activity. How can I do that? I tried with condition if my activity not running.

  • 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-01T09:28:18+00:00Added an answer on June 1, 2026 at 9:28 am

    You should probably go with

    if (response != null && response.getStatusLine().getStatusCode() == 200) { }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi I have this method below which should insert values into my database. However
I have an interface called Dictionary which has a method insert() . This interface
i have an abstract class BaseClass with a public insert() method: public abstract class
I have log4net setup and configured to insert into a sql server 2005 table.
I have a method which does a simple mysql insert, when I tried to
I have a curious issue here In my ejbCreate() method from where i insert
I have a method which takes params object[] such as: void Foo(params object[] items)
I have a query that strips data from a XML string, inserts it into
I have an XML structure like the following: <tables> <table name=tableName1> <row ID=34 col1=data
I have come a across a few different methods for inserting data into SQL

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.