如何在屏幕上显示小部件配置

时间:2010-09-26 17:20:24

标签: android button widget android-intent

我的小部件在选择放在屏幕上时会启动配置屏幕。这很好。 我希望能够触摸窗口小部件的一部分以返回到该配置屏幕。 我在我的小部件服务中创建了2个待处理的意图,但只有一个有效。代码如下:

remoteView.setOnClickPendingIntent(R.id.my_image,myWidget.makeControlPendingIntent(getApplicationContext(),BUTTON1,appWidgetId));
remoteView.setOnClickPendingIntent(R.id.TextViewBat,myWidget.makeControlPendingIntent(getApplicationContext(),BUTTON2,appWidgetId));

并且在服务开始时的那些2之前选择要做的代码:

if(command.equals(BUTTON1)){
        Intent firstIntent = new Intent(this, anotherActivity.class);
        firstIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(firstIntent); //THIS WORKS
    }
else if(command.equals(BUTTON2)){

        Toast.makeText(getApplicationContext(), "the prefs button is clicked",
                Toast.LENGTH_SHORT).show(); //THIS WORKS
        /*Intent myIntent = new Intent(Intent.ACTION_VIEW,Uri.parse("http://www.google.com"));
        myIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(myIntent);*/  //THIS WORKS

        Intent myIntent = new Intent(this,myConfiguration.class);
        myIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(myIntent); //* * * THIS CRASHES * * * *

    }

对于我的生活,我无法理解我如何再次启动配置活动。 请帮忙。

1 个答案:

答案 0 :(得分:0)

您需要做的只是致电getActivity() PendingIntentIntent即您的配置活动,并通过setOnClickPendingIntent()将其与应用小部件中的内容联系起来。以下a sample project证明了这一点。

相关问题