سؤال

I have made a working clock widget app in android but would like it so that the user could change just the clock face by clicking on it and going to a settings page. Is there a simple way of doing this? I am fairly new to programming for android.

هل كانت مفيدة؟

المحلول

You could try to use an Intent to start the settings Activity like this:

Intent intent = new Intent(context, SettingsActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
remoteViews.setOnClickPendingIntent(R.id.widget, pendingIntent);

If you use this code in the onUpdate method of the AppWidgetProvider you wrote, it should do the trick for you.

Ofcourse, SettingsActivity.class and R.id.widget need to be replaced by whatever you have called them.

If you would also like to have the settings Activity pop up automatically when first adding the widget to the home screen, you could incorporate this in you app widget provider information XML file:

android:configure="com.example.yourapplication.SettingsActivity"

In order for this to work well, you should take a look at the Android Developer pages.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top