creating custom intent

by Bob » Thu, 30 Apr 2009 09:45:48 GMT


Sponsored Links
 Hi,
Can anyone tell me what I am doing wrong, I'm sure it is real simple.
I am trying to create a custom intent but everytime I try to launch it
from another activity I get a "No Activity found to handle Intent"
error?  Am I failing to register the new intent somehow even though it
is in the manifest?


Thanks,
Bob

In other activity,produces error:

 Intent i = new Intent("com.example.Intent1");
        startActivity(i);

In Receiver Activity:

In Manifest:

 <receiver android:name=".TestBroadcastReceiver"
android:enabled="true" >
             <intent-filter>
         <action android:name="com.example.Intent1" />

            </intent-filter>
        </receiver>


In Code File:

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

public class TestBroadcastReceiver extends BroadcastReceiver {

        @Override
        public void onReceive(Context context, Intent intent) {
                // TODO Auto-generated method stub

        }

}

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



creating custom intent

by Jeff Sharkey » Thu, 30 Apr 2009 11:33:09 GMT


 So because you're targeting a BroadcastReceiver, you would call
sendBroadcast() instead of startActivity().

j






-- 
Jeff Sharkey
jshar...@google.com

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


Sponsored Links


creating custom intent

by Bob » Thu, 30 Apr 2009 12:32:37 GMT


 > So because you're targeting a BroadcastReceiver, you would call

Thanks Jeff for quick response. What I want to do is start an activity
but I tried the Broadcast Receiver because I was getting the activity
not found error with the manifest like this:

 <activity  android:name=".MyActivity"  android:label="@string/
app_name">

              <intent-filter>
         <action android:name="com.example.Intent1" />

            </intent-filter>

Is there something wrong with that used in conjunction with
startactivity()?

Thanks,
Bob





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



creating custom intent

by Jeff Sharkey » Thu, 30 Apr 2009 13:09:48 GMT


 That code should have worked, as long as "MyActivity" is directly
inside of the android:package you defined in the manifest.  If it was
deeper you would have to reference the remaining sub-package leaves in
the android:name.

For example, if you had "com.example.uistuff.MyActivity" and your
manifest was only android:package="com.example", you would need to use
android:name=".uistuff.MyActivity" when defining that activity.

j









-- 
Jeff Sharkey
jshar...@google.com

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



creating custom intent

by Bob » Thu, 30 Apr 2009 14:35:54 GMT


 hanks for your help.  I believe I have resolved the problem and it
was that I didn't have the line

<category android:name="android.intent.category.DEFAULT" />

following

<intent-filter>
<action android:name="com.example.Intent1" />


Thanks Again,
Bob


On Apr 30, 1:09am, Jeff Sharkey <jshar...@android.com> wrote:
--~--~---------~--~----~------------~-------~--~----~



Other Threads

1. How to hide views within a layout

I have some optional views in my xml layout. Namely a radioGroup and
buttons.

How can I hide these programtically?

I tried setting Visisbility, but that through an exception.

Is this documented anywhere?
--~--~---------~--~----~------------~-------~--~----~

2. Custom Object Serialization in Android?

I am writing an android client app which sends a Hashtable to a remote
servlet and recieves an ArrayList consisting of a custom Object which
is serializable.  This ran fine when I was just receiving the
ArrayList from a java console app. So I know my objects are being
serialized and deserialized properly. But when I port the same client
code over to android I get an error when trying to read the ArrayList
of my objects that is sent back from the servlet.

Is there any differences in the way Android does serialization? I
can't seem to find any documentation that says it does. The error I
receive is:

java.lang.IndexOutOfBoundsException: Invalid location

       at java.util.ArrayList.get(ArrayList.java:350)

============ My Android Client app is as
follows=================================

public class TTCPointService  {
        private Logger logger;
        private FileHandler handler;

        public TTCPointService(){

                try
                {
                        logger = 
Logger.getLogger(TTCPointService.class.getName());
                        handler = new FileHandler("ttcservice.log");
                        handler.setFormatter(new SimpleFormatter());
                        logger.addHandler(handler);
                }
                catch(IOException e)
                {
                        logger.log(Level.SEVERE,e.toString());
                }
        }

        public ArrayList<Stop> ConnectToServlet()
        {
                ArrayList<Stop> list = new ArrayList<Stop>();

        Hashtable<String, String>obj = new Hashtable<String,String>();
        obj.put("lat", "12.00");
        obj.put("log", "-23.00");

        try
        {
                URL servletURL = new URL("http://192.168.0.69:8080/
GTFSProcessor/TTCPoints");
                HttpURLConnection servletConnection = (HttpURLConnection)
servletURL.openConnection();
                servletConnection.setDoOutput(true);
                servletConnection.setDoInput(true);
                servletConnection.setUseCaches(false);
                servletConnection.setDefaultUseCaches(false);

                servletConnection.setRequestProperty("Content-
type","application/x-java-serialized-object");
                servletConnection.setRequestMethod("POST");
                logger.log(Level.INFO,"Connecting to Servlet");

                //Send object to servlet
                OutputStream os = servletConnection.getOutputStream();
                ObjectOutputStream oos = new ObjectOutputStream(os);
                oos.writeObject(obj);

                oos.flush();
                oos.close();
                logger.log(Level.INFO,"Hashtable sent to Servlet");

                //Read from servlet
                InputStream is = servletConnection.getInputStream();
                ObjectInputStream ois = new ObjectInputStream(is);


                list = (ArrayList<Stop>)ois.readObject();
                logger.log(Level.INFO,"Reading Object from Servlet");

                os.close();

        }
        catch(IOException e)
        {
          logger.log(Level.SEVERE,e.toString());
        }
        catch(ClassNotFoundException e)
        {
                logger.log(Level.SEVERE,e.toString());
        }
        return(list);
        }


}
=============The code that raises the error
is===================================

                ArrayList<Stop> list = new ArrayList<Stop>();
                TTCPointService service = new TTCPointService();
                list = (ArrayList<Stop>)service.ConnectToServlet();

                Toast.makeText(mapView.getContext(), "list contains:
"+list.get(0).getName(), Toast.LENGTH_SHORT).show();

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

3. scheme compiler for android

4. My application has died when I started to use Browser

5. Widget configuration

6. SingleTask, SingleTop how to properly implement a GUI

7. SingleTask, SingleTop how to properly implement a GUI