[英]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.
可能是因为它扩展了Application,而不是Activity。 My question is, is it possible to pass intent to a class extending Application?
我的问题是,是否可以将意图传递给扩展Application的类? I'm new to java and android so forgive me if this is a stupid question.
我是java和android的新手,所以如果这是一个愚蠢的问题,请原谅我。
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: 这是RestIntent类:
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? 我的问题是,是否可以将意图传递给扩展Application的类?
No, it is not. 不它不是。 See: http://developer.android.com/reference/android/content/Intent.html
参见: 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
. 改变你的
Application
来Activity
,如果有一些方法来实现对Application
,创建委托在应用程序中Activity
。
public class RestIntent extends Activity {
private Application application;
@Override
public void onCreate(){
super.onCreate();
application = getApplication;
SalesforceSDKManager.initNative(getApplicationContext(), new KeyImpl(), MainIntent.class);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.