Toast is not displaying in catch block - android

Hi ! I'm trying to display a mesage when the network is off or the server is not responding. My messsage is visible in LOG but does not show on screen (is not toasted). I have a sample code which works fine but my code is not.
import android.view.View.OnKeyListener;
public class AgAppHelperMethods extends Activity {
private static final String LOG_TAG = null;
private static AgAppHelperMethods instance = null;
public static String varMobileNo;
public static String varPinNo;
String[][] xmlRespone = null;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.agapphelpermethods);
}
protected AgAppHelperMethods() {}
public static AgAppHelperMethods getInstance()
{
if(instance == null)
{
instance = new AgAppHelperMethods();
}
return instance;
}
public static String getUrl ()
{
String url = "https://demo.accessgroup.mobi/";
return url;
}
public String[][] AgAppXMLParser(String parUrl)
{
String _node,_element;
String[][] xmlRespone = null;
try {
String url = AgAppHelperMethods.getUrl() + parUrl;
URL finalUrl = new URL(url);
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(new InputSource(finalUrl.openStream()));
doc.getDocumentElement().normalize();
NodeList list=doc.getElementsByTagName("*");
_node=new String();
_element = new String();
xmlRespone = new String[list.getLength()][2];
for (int i=0;i<list.getLength();i++)
{
Node value=list.item(i). getChildNodes().item(0);
_node=list.item(i).getNodeName();
_element=value.getNodeValue();
xmlRespone[i][0] = _node;
xmlRespone[i][1] = _element;
}
}
catch (Exception e)
{
Toast.makeText(getApplicationContext(), "error server not responding " + e.getMessage(),
Toast.LENGTH_SHORT).show();
Log.e(LOG_TAG, "CONNECTION ERROR FUNDAMO SERVER NOT RESPONDING", e);
}
}
}
How can I show my toast message on the screen? Thanks.

You can't do that. You can do something like this
boolean flag=true;//take globally
//working thread
.
.
.
catch (Exception e)
{
flag=false;
Log.e(LOG_TAG, "CONNECTION ERROR FUNDAMO SERVER NOT RESPONDING", e);
}
Once your working thread gets over check the flag value and show the Toast.
//Main Thread
if(!flag)
Toast.makeText(getApplicationContext(), "error server not responding " + e.getMessage(),
Toast.LENGTH_SHORT).show();
note: If you still want to show in NonUI Thread then you can use Handler or runOnUiThread()

Try this
Toast.makeText(AgAppHelperMethods.this, "error server not responding " + e.getMessage(),
Toast.LENGTH_SHORT).show();
Log.e(LOG_TAG, "CONNECTION ERROR FUNDAMO SERVER NOT RESPONDING", e);

make sure you pass right context, for example:
Toast.makeText(MyActivity.this , "error server not responding " + e.getMessage(),
Toast.LENGTH_SHORT).show();

I'm surprised this hasn't been answered yet. It appears to me all you need to do is run the Toast on the UI thread. Thus, in your catch block:
runOnUiThread(new Runnable(){
Toast.makeText(...);
});

Declare globally write it in oncreate and only show in catch block.
Toast toast;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity);
toast = Toast.makeText(ActivityDeliverables.this, "Server is not working, please contact with admin.", Toast.LENGTH_LONG);
}
try{
} catch (Exception e) {
toast.show();
}

This method is working for me if someone still need help:
getActivity().runOnUiThread(Runnable { Toast.makeText(getApplicationContext(), "Error", Toast.LENGTH_LONG).show() })

check this its working fine for me
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_location_finder);
show();
}
public void show()
{
try
{
throw new ArrayIndexOutOfBoundsException() ;
}
catch(Exception e)
{
Toast.makeText(getApplicationContext(), "HI", Toast.LENGTH_LONG).show();
}
}
}

Related

Asyntask not executing onPostExecute()

This is my Asyntask code which is not firing the onPostExecute() Any one has any idea why this might be happening???
EDIT: The Asyntask is called this way
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
FacebookSdk.sdkInitialize(getApplicationContext());
callbackManager = CallbackManager.Factory.create();
setContentView(R.layout.activity_main);
.
.
textView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(getApplicationContext(), SignUp.class);
startActivity(intent);
}
});
textView2.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(getApplicationContext(), Feedback.class);
startActivity(intent);
}
});
fbLoginButton = (LoginButton) findViewById(R.id.login_button);
fbLoginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
#Override
public void onSuccess(LoginResult loginResult) {
token=loginResult.getAccessToken().getToken().toString();
Log.v("tag", "Token:\n" + token);
try {
get_profile();
}catch (Exception ex) {
String error = ex.getMessage();
}
}
#Override
public void onCancel() {
Toast.makeText(MainActivity.this, "Login cancelled by user!", Toast.LENGTH_LONG).show();
System.out.println("Facebook Login failed!!");
}
#Override
public void onError(FacebookException e) {
Toast.makeText(MainActivity.this, "Login unsuccessful!", Toast.LENGTH_LONG).show();
System.out.println("Facebook Login failed!!");
}
});
}
The get_profile(); method is defined like this
//Method to get profile details
public void get_profile() throws UnsupportedEncodingException {
try {
// Calling async task to get json
new FetchOperation().execute();
} catch (Exception e) {
e.printStackTrace();
}
}
This is inside the Main class too
//Asynctask to get Getting fb profile details
private class FetchOperation extends AsyncTask<Void, Void, String> {
String fb_token;
#Override
protected void onPreExecute() {
super.onPreExecute();
// Get user defined values
fb_token = token;
}
#Override
protected String doInBackground(Void... params) {
String response = "";
String Urls = "https://graph.facebook.com/me?access_token=";
HttpClient httpclient = new DefaultHttpClient();
HttpGet httpget = new HttpGet(Urls +token);
HttpEntity httpEntity = null;
HttpResponse httpResponse = null;
try {
httpResponse = httpclient.execute(httpget);
} catch (ClientProtocolException e) {
e.printStackTrace();
Log.v("Response", "Hi From e1 : " + e.toString());
} catch (IOException e) {
e.printStackTrace();
}
try {
httpEntity = httpResponse.getEntity();
response = EntityUtils.toString(httpEntity);
Log.v("Response", "Hi From 2 : "+response.toString());
return response;
} catch (IOException e) {
e.printStackTrace();
Log.v("Response", "Hi From e2 : " + e.toString());
}
return null;
}
#Override
protected void onPostExecute(String jsonStr) {
super.onPostExecute(jsonStr);
Log.v("tag", "Result:" + jsonStr);
if (jsonStr != null) {
try{
JSONObject jsonObj = new JSONObject(jsonStr);
String email = jsonObj.getString("email");
String firstName = jsonObj.getString("first_name");
String lastName = jsonObj.getString("last_name");
String gender = jsonObj.getString("gender");
String country = jsonObj.getString("locale");
id = jsonObj.getString("id");
user = firstName.concat(" ");
user = user.concat(lastName);
image = "http://graph.facebook.com/" + id + "/picture?type=large";
Log.v("Fb name", "Bla bla Name : " + user);
new UploadOperation().execute();
}
catch (JSONException e) {
e.printStackTrace();
}
}
else {
Log.e("ServiceHandler", "Couldn't get any data from the url");
}
}
}
This is the last lines of the logcat
06-29 14:30:49.927 2091-2091/com.example.kmi_dev.fbloginsample V/tag﹕ Token:
CA****************************************************************xr
06-29 14:30:50.697 2091-2135/com.example.kmi_dev.fbloginsample V/Response﹕ Hi From 2 : {"id":"910***********6","first_name":"Shivanshu","gender":"male","last_name":"Verma","link":"https:\/\/www.facebook.com\/app_scoped_user_id\/910***********6\/","locale":"en_GB","name":"Shivanshu Verma","timezone":5.5,"updated_time":"2015-06-22T04:17:39+0000","verified":true}
06-29 14:31:23.827 2091-2098/com.example.kmi_dev.fbloginsample W/art﹕ Suspending all threads took: 10ms
I intend to fire another asyntask which will then save the data fetched by this asyntask into the database.
Make these changes, it will work -
private class FetchOperation extends AsyncTask<Void, Void, String>
change to - private class FetchOperation extends AsyncTask<Void, String, String> , because, you are trying to return String.
response = EntityUtils.toString(httpEntity);
change to - response = EntityUtils.toString(httpEntity).toString();
at the next line of this you have actually done it.
At the very end of doInBackground method where return null;
change to - return response;
4.No need to call super in onPostExecute()
5.Inside onPostExecute() check jsonStr is null or not and do whatever you want to do if null and if contains json data.
Your JSONObject does not contain a JSONString "email", so it is falling over at line
String email = jsonObj.getString("email");
and going straight to catch block.

Uncaught exceptions: AsyncTask never calls OnPostExecute method

I'm trying to check uncaught exceptions in any of my activities.
I put this block code after onCreate :
Thread.setDefaultUncaughtExceptionHandler(
new UncaughtExceptionHandler() {
#Override
public void uncaughtException(Thread thread, Throwable ex) {
ex.printStackTrace();
Utils.logError(MainActivity.this,session);
}
});
Utils.logError method writes logCat content to a text file and then upload with a custom AsyncTask to a FTP Server.
This is the logError method code
public static void logError(final Context ctx,final SessionManager session){
StringBuilder log=new StringBuilder();
try {
(... code that read logCat and write to a file ...)
//Upload result file to FTP with a AsyncTask
new Thread(new Runnable() {
public void run() {
if(Utils.isInternetConn(ctx)){
FTPHandler ftp = null;
ArrayList<File> archivosAcargar = new ArrayList<File>();
archivosAcargar.add(file);
ftp = new FTPHandler(ctx,archivosAcargar,session.getCodUser());
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
if(ftp.ftpConnect("server","user" ,"pass" ,21)){
ftp.execute("upload");
}
}
}
}).start();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
The AsyncTask code
EDIT:
#Override
protected String doInBackground(String... peticion) {
String res="";
if(peticion[0].equals("upload")){
if(ftpUpload()) res = "Done upload";
else res = "Error upload";
}
//This print shows "Done upload"
System.out.println(res);
return res;
}
#Override
protected void onPostExecute(String response) {
//This print not executes
System.out.println("Response " + "/" + response + "/");
if(response.equals("Done upload"))
{
System.out.println("done");
if(!isLog){ mDialog.dismiss();
//Toast
}
else{
System.exit(1);
}
}
if(response.equals("Error upload"))
{
if(!isLog)mDialog.dismiss();
}
}
The problem is that the AsyncTask is completed and the file is uploaded the (#Override) onPostExecute never is called.
I've tried to call Utils.logError without a exception and works fine but if I force a exception not works.
Can anyone help me?

Check if URL exists or not on Server

This is my code which I am using to verify, URL exists or not on Server, but always getting not exist however link is alive
Where I am doing mistake in my code, why I am always getting "doesnot exist !"
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String customURL = "http://www.desicomments.com/dc3/08/273858/273858.jpg";
boolean bResponse = exists(customURL);
if (bResponse==true)
{
Toast.makeText(MainActivity.this, "File exists!", Toast.LENGTH_SHORT).show();
}
else
{
Toast.makeText(MainActivity.this, "File does not exist!", Toast.LENGTH_SHORT).show();
}
}
public static boolean exists(String URLName){
try {
HttpURLConnection.setFollowRedirects(false);
HttpURLConnection con = (HttpURLConnection) new URL(URLName).openConnection();
con.setRequestMethod("HEAD");
return (con.getResponseCode() == HttpURLConnection.HTTP_OK);
}
catch (Exception e) {
e.printStackTrace();
return false;
}
}
}
You will get Network On Main Thread Exception
Look at NetworkOnMainThreadException
so your method always returns false because of:
catch (Exception e) {
e.printStackTrace();
return false;
}
quick fix:
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String customURL = "http://www.desicomments.com/dc3/08/273858/273858.jpg";
MyTask task = new MyTask();
task.execute(customURL);
}
private class MyTask extends AsyncTask<String, Void, Boolean> {
#Override
protected void onPreExecute() {
}
#Override
protected Boolean doInBackground(String... params) {
try {
HttpURLConnection.setFollowRedirects(false);
HttpURLConnection con = (HttpURLConnection) new URL(params[0]).openConnection();
con.setRequestMethod("HEAD");
System.out.println(con.getResponseCode());
return (con.getResponseCode() == HttpURLConnection.HTTP_OK);
}
catch (Exception e) {
e.printStackTrace();
return false;
}
}
#Override
protected void onPostExecute(Boolean result) {
boolean bResponse = result;
if (bResponse==true)
{
Toast.makeText(MainActivity.this, "File exists!", Toast.LENGTH_SHORT).show();
}
else
{
Toast.makeText(MainActivity.this, "File does not exist!", Toast.LENGTH_SHORT).show();
}
}
}
}
With a ScheduledThreadPoolExecutor:
but remember to shut down it!!
public class MainActivity extends Activity {
String customURL;
String msg = "";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
customURL = "http://www.desicomments.com/dc3/08/273858/273858.jpg";
final ScheduledThreadPoolExecutor myTimer = new ScheduledThreadPoolExecutor(1);
myTimer.scheduleAtFixedRate(new Runnable() {
#Override
public void run() {
try {
HttpURLConnection.setFollowRedirects(false);
HttpURLConnection con = (HttpURLConnection) new URL(customURL).openConnection();
con.setRequestMethod("HEAD");
System.out.println(con.getResponseCode());
if(con.getResponseCode() == HttpURLConnection.HTTP_OK){
msg = "File exist!";
}else{
msg = "File does not exist!";
}
runOnUiThread(new Runnable() {
#Override
public void run() {
Toast.makeText(MainActivity.this, msg, Toast.LENGTH_SHORT).show();
}
});
}
catch (Exception e) {
e.printStackTrace();
return;
}
}
}, 0,10000, TimeUnit.MILLISECONDS);
}
Change your exists() to this
public boolean exists(String url){
HttpURLConnection huc = ( HttpURLConnection ) url.openConnection ();
huc.setRequestMethod ("GET"); //OR huc.setRequestMethod ("HEAD");
huc.connect () ;
int code = huc.getResponseCode() ;
System.out.println(code);
if(code==200)
return true;
else
return false;
}
Use if(bResponse) instead of if(bResponse==true)
you can use the follow code to try.
final String customURL = "http://www.desicomments.com/dc3/08/273858/273858.jpg";
new Thread(){
#Override
public void run() {
// TODO Auto-generated method stub
super.run();
try {
URL url = new URL(customURL);
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setRequestMethod("HEAD");
con.connect();
Log.i(TAG, "con.getResponseCode() IS : " + con.getResponseCode());
if(con.getResponseCode() == HttpURLConnection.HTTP_OK){
Log.i(TAG, "Sucess");
}
} catch (Exception e) {
e.printStackTrace();
Log.i(TAG, "fail");
}
}
}.start();
Reason: After android 2.3, you can't perform a networking operation on its main thread,
if you do so, there will be can exception and you can't get the right result.
So if you want the application to perform a networking operation, you can use another Thread to do it.
I use this code to verify url alive. I have tested this code with image url
Example:
url = "https://ima.vn/wp-content/uploads/2017/11/ima-sofa-titan-trungkinh-1-of-3.jpg"
message = "Image url";
public void assertUrlalive(String url, String message) {
try {
URL myUrl = new URL(url);
HttpURLConnection huc = (HttpURLConnection) myUrl.openConnection();
assertEquals(huc.getResponseCode(), 200, message);
} catch (IOException e) {
e.printStackTrace();
logger.error("Connection Err: " + e.getMessage());
}
}

Android socket communcation

Im building an android application that connects to a server trough a socket. However I can't notify the mainthread from the worker connection thread, since it would lock the mainthread and android does not allow that. Here is the following code I have:
Part of connection controller:
public void run(){
while (true){
while (isRunning){
if (serverSocket == null){
try{
serverSocket = new Socket("*", *);
out = new PrintWriter(serverSocket.getOutputStream(), true);
in = new BufferedReader(new InputStreamReader(
serverSocket.getInputStream()));
}
catch (IOException e){
e.printStackTrace();
}
}
if (message != ""){
try{
System.out.println(message);
out.println(message);
message = "";
reply = in.readLine();
isRunning = false;
}
catch (IOException e) {
e.printStackTrace();
}
}
}
}
}
public void sendMessage(String path,
HashMap<String, HashMap<String, String>> variables){
this.reply = "";
isRunning = true;
String variablesJSON = JSONValue.toJSONString(variables);
this.message = path + ":" + variablesJSON;
}
Authentication class:
public boolean register(String email, String password, String displayName) {
String path = "User.register";
HashMap<String, String> variables = new HashMap<String, String>();
HashMap<String, HashMap<String, String>> user = new HashMap<String, HashMap<String, String>>();
String hashedPass;
try{
hashedPass = sha1(password);
}
catch (NoSuchAlgorithmException e){
e.printStackTrace();
return false;
}
variables.put("displayname", displayName);
variables.put("password", hashedPass);
variables.put("email", email);
user.put("User", variables);
connection.sendMessage(path, user, this);
final ProgressDialog progDailog = ProgressDialog.show(context,
"Please wait..", "Register", true);
new Thread(){
public void run(){
try{
while (ConnectionController.getInstance().getIsRunning()){
sleep(200);
}
progDailog.dismiss();
}
catch (Exception e){
e.printStackTrace();
}
}
}.start();
Toast.makeText(context.getApplicationContext(),
ConnectionController.getInstance().getReply(), Toast.LENGTH_LONG)
.show();
if (ConnectionController.getInstance().getReply() != "SUCCESS"){
return false;
}
return true;
}
I need to wait for the ProgressDialog to finish, however I can't find a way. I don't think an AsyncTask is the right way todo this since the connection needs to be open all the time. Any hints or ideas?
AsyncTask is the right way to handle this. And all that you need to do to the UI, do it in your onPost method. Infact if you want to call the async in a activity and update the views from the same activity you can
Use a Broadcast receiver
Make AsyncTask class a inner class to your activity. That way the class methods can modify the views of that activity.
I use trick 2, to get things working. Once I have them working, I take the AsyncTask out, and use BroadcastReceiver's. Just to ease my development and demo time :)

AsyncTask in onCreate method

i have a simple application that plays online radio. for showing the title from online php service i use AsyncTask and call it from onCreate method. in android 4 everythin is OK, but in android 2 it's crushed with error
java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
then in internet i found, that i must use a code like
new Thread(new Runnable() {
#Override
public void run() {
MainActivity.this.runOnUiThread(new Runnable() {
#Override
public void run() {
//my code
}
});
}
}).start();
but after i using this tip, a can't see any button and text views in my android 4 and android 2 versions. this is my code:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//thread for update title every second
new Thread(new Runnable() {
#Override
public void run() {
MainActivity.this.runOnUiThread(new Runnable() {
#Override
public void run() {
while(true) {
try {
new ShowTitle()
.execute("http://info.radiostyle.ru/inc/getinfo.php?getcurentsong=20383&mount=lezgifm");
Thread.sleep(1000);
} catch (InterruptedException e) {
String tag = "Update title";
Log.e(tag, "Update title crashed", e);
}
}
}
});
}
}).start();
}
//get title string from online source
private String getMusicTitle(String url) {
Document doc = null;
String title = "Music Title";
try {
url = "http://info.radiostyle.ru/inc/getinfo.php?getcurentsong=20383&mount=lezgifm";
InputStream input = new URL(url).openStream();
doc = Jsoup.parse(input, "CP1251", url);
title = doc.body().text();//doc.select(".products_name").first().text();
} catch (IOException e) {
Log.e(TAG, "Failed to load HTML code", e);
Toast.makeText(this, "Failed to load title", Toast.LENGTH_SHORT).show();
}
return title;
}
//class for show the audio title
private class ShowTitle extends AsyncTask<String, Void, String> {
#Override
protected String doInBackground(String... urls) {
return getMusicTitle(urls[0]);
}
protected void onPostExecute(final String result) {
lblMusicName.setText(result);
}
}
EDIT: (my working code)
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
new ShowTitle()
.execute("http://info.radiostyle.ru/inc/getinfo.php?getcurentsong=20383&mount=lezgifm");
}
private String getMusicTitle(String url) {
Document doc = null;
String title = "Music Title";
try {
url = "http://info.radiostyle.ru/inc/getinfo.php?getcurentsong=20383&mount=lezgifm";
InputStream input = new URL(url).openStream();
doc = Jsoup.parse(input, "CP1251", url);
title = doc.body().text();
} catch (IOException e) {
Log.e(TAG, "Failed to load HTML code", e);
title = "Failed to load title";
}
return title;
}
private class ShowTitle extends AsyncTask<String, String, String> {
#Override
protected String doInBackground(String... urls) {
while (true) {
String str = getMusicTitle(urls[0]);
publishProgress(str);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
String tag = "Update title";
Log.e(tag, "Update title crashed", e);
}
}
}
protected void onProgressUpdate(String... result) {
lblMusicName.setText(result[0]);
}
}
In here :
try {
//....your code here
} catch (IOException e) {
Log.e(TAG, "Failed to load HTML code", e);
Toast.makeText(this, "Failed to load title",
Toast.LENGTH_SHORT).show(); //<<< this line
}
you are trying to show Toast Message from doInBackground (from non-ui Thread). use onPostExecute for showing Toast Message or updating UI according to result returned from doInBackground
and second issue is here:
while(true) {
try {
...
Thread.sleep(1000); //<<< here calling Thread.sleep on Main UI Thread
} catch (InterruptedException e) {
String tag = "Update title";
Log.e(tag, "Update title crashed", e);
}
this will always freeze Ui Thread for after AsyncTask execution . so will need to move Thread.sleep(1000) outside runOnUiThread code block
runOnUiThread and AsyncTask are two different things. You are using it in a wrong way.
Try it like this:-
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
new ShowTitle().execute("http://info.radiostyle.ru/inc/getinfo.php?getcurentsong=20383&mount=lezgifm");
}
//get title string from online source
private String getMusicTitle(String url) {
Document doc = null;
String title = "Music Title";
try {
url = "http://info.radiostyle.ru/inc/getinfo.php?getcurentsong=20383&mount=lezgifm";
InputStream input = new URL(url).openStream();
doc = Jsoup.parse(input, "CP1251", url);
title = doc.body().text();//doc.select(".products_name").first().text();
} catch (IOException e) {
Log.e(TAG, "Failed to load HTML code", e);
title = "Failed to load title";
}
return title;
}
//class for show the audio title
private class ShowTitle extends AsyncTask<String, String, String> {
#Override
protected String doInBackground(String... urls) {
String str = getMusicTitle(urls[0]);
while(true) {
publishProgress(str);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
String tag = "Update title";
Log.e(tag, "Update title crashed", e);
}
}
return str;
}
#Override
protected void onProgressUpdate(String... progress) {
if(returnVal.startsWith("Failed")) {
Toast.makeText(this, returnVal, Toast.LENGTH_SHORT).show();
} else {
lblMusicName.setText(result);
}
}
}
You must do all the UI related task in onProgressUpdate

Categories

Resources