I want to display the message retrive from http://localhost/test/getcontent1.php in a textview of my splash screen
I have written a php file that will echo jsno data
<?php
$strorg = '[{"code":"101","message":"OK"}]';
$str = json_encode($strorg);
echo $str;
?>
the output of the link is "[{\"code\":\"101\",\"message\":\"OK\"}]"
I have written following code in splashscreen activity
public class SplashScreen extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
final TextView mTxtDisplay;
mTxtDisplay = (TextView) findViewById(R.id.txtDisplay);
String url = "http://localhost/test/getcontent1.php";
mTxtDisplay.setText("Begin");
JsonObjectRequest jsObjRequest = new JsonObjectRequest
(Request.Method.GET, url, null, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
mTxtDisplay.setText("Response: " + response.toString());
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
mTxtDisplay.setText(error.toString());
}
});
Thread timerThread = new Thread() {
public void run() {
try {
sleep(3000);
} catch (InterruptedException e) {
e.printStackTrace();
} finally {
Intent intent = new Intent(SplashScreen.this, MainActivity.class);
startActivity(intent);
}
}
};
timerThread.start();
}
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
finish();
}
}
But i didn't get any response. the textview only shows BEGIN Can sombody have any solution? As i am new to android