We help IT Professionals succeed at work.

Android code implementation question

zolf
zolf used Ask the Experts™
on
hello there,

i am trying to authenticate user with my remote db.the client uses android device to login.i have implemented the logic.but i have doubt if i am using correct standard.for e.g. from my login activity i am creating instance of ConnectiobImpl to validate user.is it correct or no.i have attached my code.please help.also i want to know about what exception do i need to catch and where.

cheers
zolf
ConnectionImpl.java
Login.java
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Author

Commented:
please help
few things:

- you should avoid using networking from the main thread, otherwise on Honeycomb onwards you get the exception (see here)

- HttpClient.execute() throws 2 exceptions, so you should catch them (and Exception as well).

- you could do it in the background AsyncTask

Author

Commented:
thanks for your feedbacks.

>>you should avoid using networking from the main thread, otherwise on Honeycomb >>onwards you get the exception
can you please give me an e.g.

>>you could do it in the background AsyncTask
what can i do in the background
- networking: have you read that link I posted? it says "StrictMode is most commonly used to catch accidental disk or network access on the application's main thread, where UI operations are received and animations take place. Keeping disk and network operations off the main thread makes for much smoother, more responsive applications. By keeping your application's main thread responsive, you also prevent ANR dialogs from being shown to users."
So in practice it will throw an exception when you execute your http requests from main thread

- async task: you can inherit from AsyncTask, show ProgressDialog and then dismiss it when you get to onPostExecute()

Author

Commented:
can you please with reference to my code.help/guide me to use the things you mentioned about StrictMode
Dev Site: http://developer.android.com/reference/android/os/StrictMode.html

what I've done when I didn't want to bother about it:

// in onCreate() of my main activity
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD)
    StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().permitAll().build());

Open in new window

Author

Commented:
thanks