Android Open Handset Developers Community

 
Guest Announcements

:arrow: Welcome: you are not yet registered; you can register here.
:arrow: A new forum on the new HTC Magic is available here.

It is currently Fri Feb 10, 2012 11:01 am

All times are UTC


 Topics   Replies   Views   Last post 
No new posts Rip Blu-ray video to Blackberry Playbook

by alex6699 on Fri Nov 26, 2010 2:56 am in Relaxing Lounge

0

217

Fri Nov 26, 2010 2:56 am

alex6699

No new posts A calls Blocker Software for Windows Mobile

by tingelsky on Tue Nov 16, 2010 7:08 am in Relaxing Lounge

0

138

Tue Nov 16, 2010 7:08 am

tingelsky

No new posts android ksoap2 Caused by: java.lang.RuntimeException: Cannot

by mindus on Thu Sep 30, 2010 6:07 am in Beginner level ANDROID developing issues

0

189

Thu Sep 30, 2010 6:07 am

mindus

No new posts Create a pdf file dynamically

by mindus on Wed Sep 22, 2010 8:47 am in Beginner level ANDROID developing issues

0

105

Wed Sep 22, 2010 8:47 am

mindus

No new posts How can I backup my mobile contacts to my pc?

by weibin.li on Tue Aug 10, 2010 7:28 am in Relaxing Lounge

1

152

Tue Aug 10, 2010 7:28 am

weibin.li




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Start a new intent without the need to click a button
PostPosted: Sun Jul 05, 2009 5:48 pm 
Offline

Joined: Sun Jul 05, 2009 5:27 pm
Posts: 3
Hi guys,

I am an android newbie; I'm developing an application and I have to finish soon because of some deadlines.
I'm facing problem about the intent/activities.

I can't find another way to run a new activity without the use of a view listener.
For example:

Code:
public final Button.OnClickListener bnt= new Button.OnClickListener() {
       public void onClick(View view) {          
          Intent i = new Intent(view.getContext(), MyActivity.class);         
          view.getContext().startActivity(i);           
       }
     };


This code always works.

But if I try to use something like the following

Code:
Intent i = new Intent("myPackage.MyActivity");         
startActivity(i);


outside an onClick method (for example in the MyActivity.onCreate method or inside the MyActivity.onActivityResults method), I always get an error.
This is the latest error I recived when I tried to run my application in the way Ive explained.

ERROR/AndroidRuntime(866): Uncaught handler: thread main exiting due to uncaught exception
ERROR/AndroidRuntime(866): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.emp/com.emp.Activity}: android.content.ActivityNotFoundException: No Activity found to handle Intent { action=com.emp.CodeActivity (has extras) }....


My need is to:
1) Run an activity clicking a button: OK
2) Get the reulst: OK
3) Automatically redirect the user to another activity to manage the results: ERROR

I don't want to let the user push a button to go ahed to the third step.

I hope I've been enough clear; thank a lot for help.

Giovanni


Top
 Profile  
 
 Post subject: Re: Start a new intent without the need to click a button
PostPosted: Mon Jul 06, 2009 2:01 pm 
Offline

Joined: Thu Dec 27, 2007 2:51 pm
Posts: 41
Hi Giovanni,
for sure you should be able to start an activity also from outside the onClick method, so in principle your code should work.. :mrgreen:

You receive the exception because the activity can not be found to execute the given Intent: have you properly declared this activity in your AndroidManifest.xml ?

Hope you find a solution for this issue.
BR


Top
 Profile  
 
 Post subject: Re: Start a new intent without the need to click a button
PostPosted: Mon Jul 06, 2009 2:06 pm 
Offline

Joined: Thu Dec 27, 2007 6:09 pm
Posts: 65
Hi,
I suggets to try the class variant of the Intent constructor:

Code:
Intent i = new Intent(this, MyActivity.class);


Top
 Profile  
 
 Post subject: Re: Start a new intent without the need to click a button
PostPosted: Mon Jul 06, 2009 7:44 pm 
Offline

Joined: Sun Jul 05, 2009 5:27 pm
Posts: 3
The activity class is reistered into the manifest, infact it works when I start it inside an onclick method.
I'm not able to execute it inside the startActivityForResult.

This works...

Code:
public final Button.OnClickListener search = new Button.OnClickListener() {
       public void onClick(View view) {          
          Intent i = new Intent(view.getContext(), MyActivity.class);         
          view.getContext().startActivity(i);           
       }
     };


This doesn't....

Code:
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
     if (requestCode == 0) { //Scanner
           if (resultCode == RESULT_OK) {
               startActivity(new Intent(MyActivity.class));
           } else if (resultCode == RESULT_CANCELED) {
               // Handle cancel
           }
       }    
  }


Another thing: I was wrong when I posted the error message... this was releated to another error.
I really can't view the error message cause the only way I have to test the application is on an android based mobile; this because the onActivityResult method is referred to an activity that execute an external application that is not installed in the emulator.
The external application is correctly called but when it finishes its lifecycle, if I invoke the startActivity(new Intent(MyActivity.class)); inside the onActivityResult the application fails the execution. Otherwise it correctly come back to the previous activity.

Thanks in advance for help,

Giovanni


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
SitemapIndex SitemapIndex RSS Feed RSS Feed Channel list Channel list
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
phpBB SEO

This site is not affiliated with nor endorsed by the Open Handset Alliance.
All trademarks and logos used in this site are of properties of their respective owners.