Wednesday, 15 June 2011

java - Running a client/server through a fragment in android -



java - Running a client/server through a fragment in android -

i'm trying connect java server android client (which i've achieved 1 simple activity). want add together list/details fragment , able pass info , server , list , details. i'm using illustration list/details view fragment:

android fragments example

i have 3 questions:

is possible run server fragment , pass info , server? would have connection start in main activity or of fragments? if in main activity, how pass info 4th fragments main activity?

i quite new android , still learning why inquire unusual questions.

many thanks!

1) cannot run server communication on fragment. mean is, has run on different thread on ui thread. fragment runs on ui thread.

you can technically write "server" code on same class fragment long runs on different thread know - fragments have lifecycles means 1 time user moves fragment/activity or goes launcher - server , communication killed!

you should create android service communication stuff , keeps running in background when application hidden/not running (as see fit).

2) start connection once, no need start every fragment/activity.

3) there lots of ways passing around data. happens intents, read it.

implementation may differ, of import thing remember not run long duration tasks on main thread since create application freeze , hence killed android.

java android android-fragments

No comments:

Post a Comment