Is it possible to launch an activity on a certain key sequence?

by BillS » Thu, 18 Feb 2010 22:54:55 GMT


Sponsored Links
 For example, typing "321" launches my application.

Thanks

--



Other Threads

1. Catching exceptions globally

Hi all,


in my application I would like to catch all exceptions globally - it
should not matter, where those exceptions occur. Some runtime
exceptions are practically impossible to catch (OutOfMemoryError for
instance), but I want to show an informative dialog and resume
execution at some well-defined point (main menu activity or
something).

Using Thread.setDefaultUncaughtExceptionHandler() does this for
background threads, but it is of no help in the UI thread (or adjacent
handlers). If an exception occurs in the UI thread, the UI will be
jammed - not reacting to any key or touch events anymore. Of course,
this seems natural since it did not catch that exception; but I wonder
if there is a way to recover the UI thread. So:

 - Can I recover / restart the UI thread after an uncaught exception
(from another thread) ?
 - Is there another way to catch uncaught exceptions globally ?
 - Are there viable alternatives to handle this problem ?


Thx in advance
--~--~---------~--~----~------------~-------~--~----~

2. costum list adapter:big problem

Hi!

  I have an costum list adapter ItemAdapter(which contain  Item objects).
I made a new class ParserxmL for parse data from a xml file and all objects
created by parser are added to an ArrayList<Item>.i have a getter to return
this list.
In my activity i want as my adapter to get data from this list of results
and to put in a listview.

the big problem is that:my adapter do not contain all data from my list and
just the first results are loaded corect and everytime when i put more
objects in adapter and call setListAdapter() just those results are loaded
again and again..

so if my adapter contains obj1,obj2,obj3 when it is loaded for the first
time my list will display obj1,obj2,obj1..and next time when i put something
more in adapter th results are the same.

here is the code:


<ItemAdapter>
import java.util.ArrayList;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

public class ItemAdapter extends BaseAdapter{

    private ArrayList<Item> items;
    private Context         context;

    public ItemAdapter(Context context_)
    {
        context = context_;
        items = new ArrayList<Item>();

    }

    public void addItem(Item item)
    {
        items.add(item);
    }

    public int getCount()
    {
        return items.size();
    }

    public Object getItem(int position) {

        return items.get(position);
    }

    public long getItemId(int position) {

        return position;
    }

    public View getView(int position, View convertView, ViewGroup parent)
    {
        Item itm;

        if(convertView == null)
        {

            itm = new Item(context);

            itm.setTitleText(items.get(position).getTitleText());

            itm.setImage(items.get(position).getImage());
            itm.setSecondLineText(items.get(position).getStreet(),
                                  items.get(position).getZIP(),
                                  items.get(position).getCity());

            itm.setArrowResources(items.get(position).getArrowResources());

        }
        else
            itm = (Item)convertView;

        return itm;
    }

    public boolean areAllItemsSelectable() {
        return true;
    }

    public boolean isSelectable(int position) {
        return  items.get(position).isSelected();
    }


    public void setList(ArrayList<Item>list)
    {
        items = list;
    }

}

</ItemAdapter

<MyActivity>


import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import org.apache.http.util.ByteArrayBuffer;

import android.R.integer;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.app.AlertDialog.Builder;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ListAdapter;
import android.widget.ListView;



public class ResultsActivity extends Activity implements  Runnable{

    private ListView            list_results;
    private ProgressDialog     load_result_progress;
    private ItemAdapter        adapter;
    private URL                url;
    private String               what  = " ";
    private String               where = " ";
    private String               url_source;
    private int                offset = 0;
    private Button              button_more_results;
    private Bundle            extra_info;
    private ResultsActivity result_activity_handle;
    private Builder            info_window;

    private Handler        handler = new Handler()
            {
                @Override
                public void handleMessage(Message msg)
                {
                    load_result_progress.dismiss();
                    list_results.refreshDrawableState();
                    list_results.setAdapter(adapter);
                }
            };


    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.results_layout);

        result_activity_handle = this;

        list_results          = (ListView)findViewById(R.id.list_results);
        button_more_results  = (Button)
findViewById(R.id.more_results_button);
        load_result_progress = ProgressDialog.show(this, "Loading...",
"Downloading results...", true,false);
        adapter                 = new ItemAdapter(getApplicationContext());
        Bundle bundle          = getIntent().getExtras();
        info_window             = new AlertDialog.Builder(this);



        if(bundle != null)
        {
            what  = bundle.getString("INPUT_WHAT_TEXT");
            where = bundle.getString("INPUT_WHERE_TEXT");
        }

        Log.e("STRINGS", what);
        Log.e("STRINGS", where);
        Log.e("OFFSET",Integer.toString(offset));



        Thread t = new Thread(this);
        t.start();

        button_more_results.setOnClickListener(new OnClickListener()
        {
         @Override
         public void onClick(View arg0)
             {

                 if(adapter == null || extra_info == null)
                 {
                     info_window.setTitle("Error");
                     info_window.setMessage("Adapter or extra info are
null");
                     info_window.show();
                 }
                 else
                 {
                     int count =
Integer.parseInt(extra_info.getString("RESULT_COUNT"));

                     if(count >  adapter.getCount())
                     {
                         offset++;

                         load_result_progress.show();
                         Thread t2 = new Thread(result_activity_handle);
                         t2.start();
                     }
                     else
                     {
                         info_window.setTitle("Info");
                         info_window.setMessage("No more results!");
                         info_window.setPositiveButton("ok",null);
                         info_window.show();
                     }
                 }
             }
        });
    }


    public String getXMLFile(URL myURL) throws IOException
    {
        String myString;

        try{


        URLConnection ucon = myURL.openConnection();


        InputStream is = ucon.getInputStream();
        BufferedInputStream bis = new BufferedInputStream(is);


        ByteArrayBuffer baf = new ByteArrayBuffer(50);
        int current = 0;
        while((current = bis.read()) != -1){
           baf.append((byte)current);
        }


        myString = new String(baf.toByteArray());
        } catch (Exception e) {

         myString = e.getMessage();
        }
        return myString;
}


    @Override
    public void run() {
        try {

        url_source = "xml_url";
        url = new URL(url_source);

        Log.e("DEBUG",url.toString());

        my_xml_content = getXMLFile(url);
        Log.e("XML",my_xml_content);

        ArrayList<Item> results_items = new ArrayList<Item>();
        ParserxmL p = new ParserxmL(getApplicationContext(),my_xml_content);
        int i;

        results_items = p.getItemsList();
        extra_info      = p.getExtraInfo();

        Log.e("TEST",results_items.get(results_items.size() -1).getZIP());
        Log.e("DEBUG",Integer.toString(results_items.size()));


        for(i = 0; i < results_items.size(); i++)
            adapter.addItem(results_items.get(i));





        } catch (MalformedURLException e1) {

            e1.printStackTrace();
        } catch (IOException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }

        handler.sendEmptyMessage(0);

    }

}


</MyActivity>

I tried a lot to fix that bug but i don't have any more ideeas...

Thank you very much!

--~--~---------~--~----~------------~-------~--~----~

3. Getting error: The icon for your application is not valid. Please use a 48x48 PNG

4. "Share" menu

5. Spinner that looks like an EditText - Head is bloody and bruised

6. Singtel G1

7. Intent to pick appwidget?