简体   繁体   中英

Pass an intent from activity to a class extending Application

I was a given a module that I have to integrate on the application that I'm currently doing. But I am sort of lost when I encountered a class that extends an Application. What I'm trying to do is to pass intent to that class when a button is clicked. But I get an error in my manifest when I include the class. Probably because it is extending Application, not an Activity. My question is, is it possible to pass intent to a class extending Application? I'm new to java and android so forgive me if this is a stupid question.

Here's my manifest:

<activity
        android:name=".RestIntent"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
</activity>

Here's the RestIntent class:

public class RestIntent extends Application {

     @Override
     public void onCreate(){
         super.onCreate();
         SalesforceSDKManager.initNative(getApplicationContext(), new KeyImpl(), MainIntent.class);
     }

}

My question is, is it possible to pass intent to a class extending Application?

No, it is not. See: http://developer.android.com/reference/android/content/Intent.html

Intents are received by Activities, BroadcastReceivers and Services, but not by Application objects.

change your Application to Activity , if there are some methods to implement for the Application , create a delegate to your application in Activity .

public class RestIntent extends Activity {

     private Application application;

     @Override
     public void onCreate(){
         super.onCreate();
         application = getApplication;
         SalesforceSDKManager.initNative(getApplicationContext(), new KeyImpl(), MainIntent.class);
     }

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM