Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7059025
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:10:58+00:00 2026-05-28T04:10:58+00:00

I check if a string is NULL in a Thread, if its null, the

  • 0

I check if a string is NULL in a Thread, if its null, the Handler starts
a Runnable which starts a new Activity.

Everything works fine, but, after the new activity is displayed it switches back to the calling Activity and it crashes.

Here is a code snippet.

if(username==null)
{
    dialogs.dismiss();
    handlers.post(new MyRunable());
}

and Runnable is

public class MyRunable implements Runnable
{
    public void run(){

    Toast.makeText(ListActivity.this, "Your Connection is too slow",Toast.LENGTH_LONG).show();

    startActivity(new Intent(ListActivity.this,Anim.class));

    }
}

Here is my Full Source

    package com.cram;

    import java.io.File;
    import java.io.IOException;

    import javax.xml.parsers.ParserConfigurationException;

    import org.xml.sax.SAXException;
    import android.app.Activity;
    import android.app.AlertDialog;
    import android.app.ProgressDialog;
    import android.content.Context;
    import android.content.DialogInterface;
    import android.content.DialogInterface.OnClickListener;
    import android.content.Intent;
    import android.database.Cursor;
    import android.graphics.Typeface;
    import android.net.ConnectivityManager;
    import android.net.NetworkInfo;
    import android.os.Bundle;
    import android.os.Handler;
    import android.util.Log;
    import android.widget.ListView;
    import android.widget.TextView;
    import android.widget.Toast;

    public class BuddyListActivity extends Activity
    {

        String ss;
        private static ProgressDialog dialogs,dialog;
        private Thread downloadThreads;
        boolean results=false;
        Context ctx;
        String[]ddd;
        ListView lv1;
        String [] icons;
        BuddyDbAdapter adapter;
        NetworkInfo netinfo;
        Cursor cursor;
        String values;
        GetBuddy gb;
        BuddyDB db;
        String[] username;
        String[] firstname;
        String[] lastname;
        String[] avatar;
        String[] id;
        File[] iconss;
        Handler handlers;
        boolean ready=false;


        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.buddy);
            db=new BuddyDB(BuddyListActivity.this);
            Typeface font = Typeface.createFromAsset(getAssets(),"fonts/Fortheloveofhate.ttf");
    TextView btxt = (TextView) findViewById(R.id.textbuddy);
    btxt.setTypeface(font);
    ctx=getApplicationContext();    
    lv1=(ListView)findViewById(R.id.list22);
    netinfo=null;
    adapter=new BuddyDbAdapter(BuddyListActivity.this);
    netinfo=checkDataConnection(getApplicationContext());
    handlers = new Handler();
    adapter.open();

    if(netinfo!=null)
    {   
        downloadThreads = (Thread) getLastNonConfigurationInstance();
        if (downloadThreads != null && downloadThreads.isAlive()) {
        dialog = ProgressDialog.show(this, "Download", "downloading");
        }

        startdownload();

    }




    if(netinfo==null)
    { 

        cursor=adapter.showBuddy();         
        if (cursor==null||cursor.moveToFirst()==false) 
        {
             AlertDialog.Builder buddybox = new AlertDialog.Builder(this);
                buddybox.setMessage("You have No Buddies Yet douche!!");
    buddybox.setNeutralButton("Okay", new OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {

                        startActivity(new Intent(getBaseContext(),Anim.class));
                    }
                });
                buddybox.setCancelable(false);
             buddybox.show();
    }
        else
            {
            cursor.moveToFirst();   
            int j=0;
            ddd=new String[cursor.getCount()];
            icons=new String [cursor.getCount()];
                do
                {
            String firstName = cursor.getString(cursor.getColumnIndex(BuddyDbAdapter.BUDDY_FISTNAME));
            String lastname  = cursor.getString(cursor.getColumnIndex(BuddyDbAdapter.BUDDY_LASTNAME));
            String Avatar    = cursor.getString(cursor.getColumnIndex(BuddyDbAdapter.AVATAR));
            ddd[j]=firstName+" "+lastname;
    Log.d("Test", ddd[j]);
    icons[j]=Avatar;
    Log.d("Test", icons[j]);
    j++;
        }while(cursor.moveToNext());


        iconss= new File[icons.length];
        Log.d("Test",icons.length+"");
    for (int q = 0; q < icons.length; q++) {
        iconss[q] = new File(Download.ROOT +"/"+ icons[q]+".jpg");
    Log.d("Test", iconss[q].getAbsolutePath().toString());
    }
    //adapter.close();
                    lv1.setAdapter(new BuddyAdapter(BuddyListActivity.this,R.layout.list1,ddd,iconss));
                    onDestroy();
                }



            }
        }

    private void box() {
        // TODO Auto-generated method stub

    cursor=adapter.showBuddy(); 
    if (cursor==null||cursor.moveToFirst()==false) 
    {
        dialogs.dismiss();
         AlertDialog.Builder buddybox = new AlertDialog.Builder(this);
            buddybox.setMessage("You have No Buddies Yet ass!!");
    buddybox.setNeutralButton("Okay", new OnClickListener() {
                        public void onClick(DialogInterface dialog, int which) {

                            startActivity(new Intent(getBaseContext(),Anim.class));
                        }
                    });
                    buddybox.setCancelable(false);
                 buddybox.show();

        }

        }

        private NetworkInfo checkDataConnection(Context applicationContext) {
        final ConnectivityManager connMgr = (ConnectivityManager)BuddyListActivity.this.getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo networkinfo=null;
        final android.net.NetworkInfo wifi =connMgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
        final android.net.NetworkInfo mobile =connMgr.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
        if(wifi.isConnected()||mobile.isConnected())
        {networkinfo=connMgr.getActiveNetworkInfo();
         return networkinfo;
        }

        else
        {
            return null;
        }

    }
        @Override
        protected void onDestroy() {
            super.onDestroy();
            if (adapter != null) {
                adapter.close();
            }

        }

        @Override
        protected void onStop()
        {
            super.onStop();
            finish();

        }
        private void startdownload() {
            dialogs = ProgressDialog.show(BuddyListActivity.this, "Contacting Our Servers", "Geting Your Buddies Avatar");
        downloadThreads = new MyThread();
        downloadThreads.start();

    }

    public class MyThread extends Thread {

        @Override
        public void run() {
            try {

                new Thread();
                GetBuddy tt=new GetBuddy();
                String xml=tt.get();
                if(xml==null)
                {   dialogs.dismiss();
                    handlers.post(new MyRunable());
                    ready=false;
                    //downloadThreads.suspend();

    }
    final Download cd = new Download();
    results = cd.downloadBitmap();
    if(results)
    {
    BuddyParse bp=new BuddyParse();

    try {

        username=bp.show(xml);
    //                  if(username==null)
    //                  {   dialogs.dismiss();
    //                      handlers.post(new MyRunable());
    //                      //downloadThreads.suspend();
    //                  }
        firstname=bp.firstname();
        lastname=bp.lastname();
        avatar=bp.avatar();
        id=bp.id();
        adapter.deleteAll();
        ready=true;
    } 
    catch (ParserConfigurationException e) 
    {
        e.printStackTrace();
    }
    catch (SAXException e) 
    {
        e.printStackTrace();
    } 
    catch (IOException e) 
    {
        e.printStackTrace();
    }
    //  Log.d("len", username.length+"");

    for(int k=0; k<username.length;k++)
    { 
    adapter.insertBuddy(id[k], username[k], firstname[k], lastname[k], avatar[k]);
    Log.d("Test", id[k]+username[k]+firstname[k]+lastname[k]+avatar[k]+"");
    }
    box();
    cursor=adapter.showBuddy();
    cursor.moveToFirst();
    int i=0;
    ddd=new String[cursor.getCount()];
    icons=new String [cursor.getCount()];
        do
        {
    String firstName = cursor.getString(cursor.getColumnIndex(BuddyDbAdapter.BUDDY_FISTNAME));
    String lastname  = cursor.getString(cursor.getColumnIndex(BuddyDbAdapter.BUDDY_LASTNAME));
    String Avatar    = cursor.getString(cursor.getColumnIndex(BuddyDbAdapter.AVATAR));
    ddd[i]=firstName+" "+lastname;
    Log.d("Test", ddd[i]);
    icons[i]=Avatar;
    Log.d("Test",icons[i]);
    i++;
        }while(cursor.moveToNext());


     iconss= new File[avatar.length];
    for (int k = 0; k < avatar.length; k++) {
        iconss[k] = new File(Download.ROOT+"/"+avatar[k]+".jpg");

    Log.d("Test", iconss[k].getAbsolutePath()+"thread");
    //Log.d("Test", ddd[k]);
            }

        if (results&&ready)
            {
            dialogs.dismiss();
            handlers.post(new MyRuns());

            }
    } 
    //              else
    //              {   dialogs.dismiss();
    //                  handlers.post(new MyRunable());
    //                  
    //              }
            }finally {

            }

        }


    }

    public class MyRuns implements Runnable {
        public void run() {
            ready=true;
            lv1.setAdapter(new BuddyAdapter(ctx,R.layout.list1,ddd,iconss));
            onDestroy();
        }
    }
    public class MyRunable implements Runnable {
        public void run() {
            //Toast.makeText(BuddyListActivity.this, "Your Connection is too slow", Toast.LENGTH_LONG).show();
                startActivity(new Intent(BuddyListActivity.this,Anim.class));


            }
        }
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T04:10:59+00:00Added an answer on May 28, 2026 at 4:10 am

    Setting RETURN in the try catch block and setting
    android:noHistory="true" in Android Manifest for all activities fixed my problem

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I want to check for the null string I would do [ -z
I have this: If String.IsNullOrEmpty(editTransactionRow.pay_id.ToString()) = False Then stTransactionPaymentID = editTransactionRow.pay_id 'Check for null
I have classX: Sub New(ByVal item_line_no As String, ByVal item_text As String) ' check
I continuously check string fields to check if they are null or blank. if(myString
Could any one give me an idea to check whether a string is null
I want the login activity to start when the user starts the app but
This thread is a continuation of Is there a reason to check for null
Our application is developed using Spring framework. Is it good practice to check null
I need to check a string to see if any word in it has
How can I check a string in php for specific characters such as '#'

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.