0

In my main Activity's onCreate method, I've started a Intent using the following code:

Intent intent = new Intent(this, NetworkHandler.class);
startService(intent);

I've created another class named NetworkHandler which extends the IntentService

public class NetworkHandler extends IntentService {
    public NetworkHandler() {
        super("HTTPRequest");
        // TODO Auto-generated constructor stub
    }

    @Override
    protected void onHandleIntent(Intent intent) {
        String url = "http://vlm1.uta.edu/~zhangzhong/questions.json";
        Toast.makeText(intent.getComponent(), "Debug!", Toast.LENGTH_LONG).show();
        DefaultHttpClient client = new DefaultHttpClient();

The problem is I'm trying to use the Toast in the NetworkHandler class. I'd like to pass the main activity object to the first parameter of makeText method of Toast. How can I do it?

4

2 回答 2

1

您可以传递getApplicationContext()this作为 的第一个参数makeText()

于 2013-04-23T01:20:00.210 回答
0

你需要的是一个上下文。幸运的是,IntentService 是一个上下文,所以只需使用this!

于 2013-04-23T01:14:58.577 回答