0

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...?

2
Contributors
11
Replies
12
Views
5 Years
Discussion Span
Last Post by JamesCherrill
Featured Replies
  • What's stopping you from creating an activity class that extends android.app.Activity or one of its subclasses? [url]http://developer.android.com/reference/android/app/Activity.html[/url] Read More

0

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.

0

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.

0

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..?

Edited by kishanillur: n/a

0

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();
}


}

0

Yes, except you will have your own Activity subclass:

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

...

Activity e = new MyActivity(someURL);
0

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...?

Edited by pyTony: fixed formatting

0

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?

0

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...?

Edited by pyTony: fixed formatting

0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.