Multiple inheritance in java

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Kishan
    New Member
    • Jul 2011
    • 1

    Multiple inheritance in java

    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, broadcastReceiv er( 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.

    Code:
    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...?
    Last edited by Meetee; Jul 13 '11, 09:13 AM.
  • Dheeraj Joshi
    Recognized Expert Top Contributor
    • Jul 2009
    • 1129

    #2
    You create a class extends BroadcastReceiv er and then create a class which extends Activity and with a action method (to open browser).

    Activity class can be singleton as well (I am guessing this after reading your post. I am not sure how is your design).

    If you receive the new SMS. If no activity object present you create one and call its action method. If the it is present use the existing object, and call its action method.

    Regards
    Dheeraj Joshi

    Comment

    Working...