I am writing some application for Android. Here my app receives sms and as soon as it receives, it launches another activity,say a browser with some url supplied.

So here, I need two classes, broadcastReceiver( to receive sms) and Activity. But in java i can inherit only 2 classes. Since they are imported from android library, I am not getting how I can implement this. I think I cant use interfaces also.

import android.app.Activity;
import android.content.BroadcastReceiver;

public class SmsReceiver extends BroadcastReceiver
{
receive sms;

if it satisfies some criteria,
launch a new acivity....


}

here, i have no means to extend or use Activity class,
can anyone suggest me a way...?

Nothing in fact. Okay, suppose that I create one class that extends Activity. How can I launch it from within Smsreceiver class...? For that, I need Smsreceiver class to inherit Activity class again. This is the problem. I have shown SmsReceiver class in my previous post.

For that, I need Smsreceiver class to inherit Activity class again. This is the problem. I have shown SmsReceiver class in my previous post.

No, Smsreceiver class does not have to inherit Activity. This misunderstanding is probably why you are having a difficulty here.
You create a new instance of your Activity subclass just like you would create a new instance of anything else, no need to inherit from it.

I tried it. But it did not work, could you please show me how I can do it...?
Can you use the same class I have in my post..?

Is it like this...?

import android.app.Activity;
import android.content.BroadcastReceiver;

public class SmsReceiver extends BroadcastReceiver
{
receive sms;

if it satisfies some criteria,
{
Activity e = new Activity();
creating some intent to open browser...
e.startActivity();
}


}

Yes, except you will have your own Activity subclass:

class MyActivity extends Activity {
  public MyActivity(URL url) {
     ...
  }
  ...
}

...

Activity e = new MyActivity(someURL);

Thanks a lot... but sorry that its not working.
What i did exactly is,

import android.content.BroadcastReceiver;
import android.app.Activity;
class MyActivity extends Activity
{
   public MyActivity(Intent m)
   {    
      startActivity(m);
   }  
}   
public class SmsReceiver extends BroadcastReceiver
{

    @Override
    public void onReceive(Context context, Intent intent) 
    {


     ....
     ....
     Uri address = Uri.parse("http://www.google.com");
     Intent m = new Intent(Intent.ACTION_VIEW,address);
     Activity e = new MyActivity(m);
   }
}

Whats wrong in it...?

At a quick look nothing jumps out at me, that looks like the right approach, but "its not working" gives me nothing to go on. I'm going to be offine till tomorrow, but in the meantime you could document exactly what's going wrong - including any exceptions etc. Maybe someone else can help while I'm away?

Ya you are right.. Thank you.

In the above code, there is some runtimeException. May be I am not creating the object of activity subclass properly or I am not using it properly. I caught it in those two statements.
I used,

   try
       {
        myActi e = new myActi();
        e.startActivity("http://www.google.com");
       }catch(RuntimeException f){ 

           System.out.println("Exception: "+f.getMessage()); 
                              }

Whats wrong with the code...?

Are you joking?
The runtime exception includes the exact reason for the error, and the exact line of your program where it happened. Is there some reason why you want me to tell you what's wrong with your program, but you won't tell me what the exception says?

Replace your catch block with f.printStackTrace(); and report the output back here. Also post the code where the exception happened and identify the exact line that the exception refers to.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.