If you think the Android project inbox-android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
package com.inboxapp.androidsdk.scratchpad;
/*fromwww.java2s.com*/import android.app.Activity;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;
import com.inboxapp.androidsdk.R;
import com.inboxapp.androidsdk.scratchpad.scratchpad_apis.TestApi;
publicclass Scratchpad_MainActivity extends Activity
{
@Override
protectedvoid onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
publicboolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
publicboolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
@Override
publicvoid onResume()
{
super.onResume();
new apiTask().execute();
}
privateclass apiTask extends AsyncTask<String, Integer, String> {
protected String doInBackground(String... urls) {
if (isCancelled())
return null;
try {
String okhttpGson= (new TestApi()).GET_with_OKHTPP_with_GSON();
String okhttpJackson= (new TestApi()).GET_with_OKHTPP_with_JackSON();
return (new TestApi()).GET_with_RETROFIT();
}
catch(Exception e)
{
Log.w("API Request Exception","\n Message: " + e.getMessage() + "\n Localized Message: " + e.getLocalizedMessage() + "\n Cause: " + e.getCause());
return"Exception";
}
}
protectedvoid onProgressUpdate(Integer... progress) {
//do something with UI
}
protectedvoid onPostExecute(String result)
{
String text = result;
if (result == null)
{
text = "cancelled!!";
}
if (result.equals("Exception"))
{
text = "Exception";
}
Toast toast = Toast.makeText(Scratchpad_MainActivity.this, text, Toast.LENGTH_SHORT);
toast.show();
}
}
}