What is the purpose of a receiver for APPWIDGET_UPDATE - android

I'm working on an Android app written by someone no longer with the company, and not understanding what the purpose is of creating a receiver for AppWidget updates. The manifest has the main activity which runs when the app is launched. As far as I can tell, the appwidget is never used and its code is separate from the rest of the app. I can't tell if this is a left-over and can be removed or if it is still in use. All of the tutorials and examples I find explain how to implement this, but not really why one would, especially in this case.
Code from the manifest file:
<application
android:debuggable="true"
android:icon="#drawable/icon"
android:label="#string/app_name"
android:theme="#style/ConnectTheme" >
<activity
android:name="com.globalcrossing.connect.ConferenceListView"
android:label="#string/listTitle" >
<intent-filter android:label="#string/app_name" >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.globalcrossing.connect.Preferences"
android:label="#string/set_preferences" >
</activity>
<!-- Broadcast Receiver that will process AppWidget updates -->
<receiver
android:name="com.globalcrossing.connect.ConferenceWidget"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
<meta-data
android:name="android.appwidget.provider"
android:resource="#xml/widget_provider" />
</receiver>
... more activities I understand, deleted for brevity
</application>

as in Doc:
ACTION_APPWIDGET_UPDATE :
Sent when it is time to update your AppWidget.
means ACTION_APPWIDGET_UPDATE Action faire when:
1. an new instance of Your AppWidget added to Home Screen from AppWidget Chooser( from AppWidget provider),
2. when requested update interval having lapsed which you have provided in AppWidget meta-data file using android:updatePeriodMillis attribute , and
3. when device reboot

If the application has a corresponding home screen widget, which can be found under the widgets section in the all programs list, then you will need APPWIDGET_UPDATE. Otherwise it will be unnecessary noise to your application with no purpose.

Related

Running android apps particular activity independently than rest of activities

THIS QUESTION IS SOLVED, PROVIDING ANSWER FOR FUTURE SO VISITORS BELOW
Context :
I am developing a default phone app. Which handles action.DIAL and action.CALL from My application as well as it handles these both intents from other apps too.
What is problem :
If my CallActivity is running ( if any call is ongoing ) then -
When i again try to open my app, it is presenting me CallActivity only.
And because of this i am unable to make another call by opening my app.
What manifest.xml looks like :
<application
android:allowBackup="true"
android:directBootAware="true"
android:fullBackupContent="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:theme="#style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.CALL_BUTTON" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
</activity>
<activity
android:name=".CallActivity"
android:label="#string/title_activity_call"
android:process=":CallManager"
android:screenOrientation="portrait"
android:theme="#style/AppTheme.NoActionBar">
<intent-filter android:priority="800">
<action android:name="android.intent.action.ACTION_CALL" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
</activity>
</application>
What i found when searched for the said problem :
How can I launch an independent activity to my application as well as the application of phone launches the activity to make calls?
https://stackoverflow.com/questions/9458300/how-to-create-an-android-activity-and-service-that-use-separate-processes
What are my efforts taken :
You can note i tried android:process=":CallManager" attribute in manifest for my CallActivity
Did that solved the issue :
Nope. I am still unable to open my MainActivity, whenever CallActivity is running. But is caused the problem that now my call is not getting ended as this is completely another process it is unable to reference other calls which remain there in older process.
ANSWER
Did android:process was correct :
No not at all in this case, as it is used when our app memory usage increases over particular limit android starts caching its services and resources in order to avoid it developers generally use android:process which allows them another heap memory available with same heap size.
** What was problem :**
It was related to task and its affinities
Both activities needed to be separated for tasks and their affinities
like :
<activity
android:name="com.example.ActivityA"
android:label="Activity A"
android:launchMode="singleInstance"
android:taskAffinity="com.example.AffinityA" >
</activity>
<activity
android:name="com.example.ActivityB"
android:label="Activity B"
android:launchMode="singleInstance"
android:taskAffinity="com.example.AffinityB" >
</activity>
I must thanks #JayWozz for his answer over SO https://stackoverflow.com/a/45488126/9810130 and must appreciate #gabe-sechan for his sincere help and efforts and for giving his value-able time for this thread.
I think you're basically asking for a new stack of activities. Try launching the intent with FLAG_ACTIVITY_NEW_DOCUMENT| FLAG_ACTIVITY_MULTIPLE_TASKS That will launch the activity as if its a new set of activities, with its own separate listing in the recent apps list. See the definiton of these flags at https://developer.android.com/reference/android/content/Intent

BootReceiver doesen't work

I know this has been asked tons of times, and there are hundreds of example on internet, but i want to understand what's wrong in my code.
As the title suggest i want to execute some code while the phone turn on, specifically i want to set some Alarms for getting notifications, but that's not relevant now, my problem is that the boot receiver onReceive method is never called apparently
I have the right permissions in the manifest:
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
And i've also registered the receiver in the manifest
<receiver
android:name=".BootBroadcastReceiver"
android:enabled="true" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
And I've already created the receiver class
public class BootBroadcastReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context pContext, Intent intent) {
Toast.makeText(pContext,"waiting for debugger",Toast.LENGTH_LONG).show();
android.os.Debug.waitForDebugger();
//Stuff for the alarms
}
}
Can someone explain me what i'm a failing without posting always the same examples that i see everywhere?
I want to know what's wrong in my code, not how it should be done.
PS: : I forgot to say that i need to stop the code for debugging the alarm things, but i don't think that's the problem since it doesen't even show the Toast.
UPDATE: full manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="feddycapdev.conapo.turnario" >
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Calendario"
android:label="#string/title_activity_calendario"
android:screenOrientation="portrait" >
</activity>
<activity
android:name=".Settings_Activity"
android:label="#string/title_activity_settings_" >
</activity>
<activity
android:name=".SettingGiorno"
android:label="#string/title_activity_setting_giorno" >
</activity>
<receiver
android:name=".BootBroadcastReceiver"
android:enabled="true" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
<service android:enabled="true" android:name=".WebNotificChecker" />
<service android:enabled="true" android:name=".Sveglia" />
<service android:enabled="true" android:name=".NotificaVigilanza" />
</application>
</manifest>
I should run the activity before the receiver?
Something has to use an explicit Intent to start one of your application's components before any manifest-registered receivers will work. For 99% of Android apps, that means that the user has to start your app from the home screen. If your app is serving as a plugin to some other app, you may not need the activity — please discuss this with the developers of the app that would be hosting your plugin.
how can I set notification if the user doesn't open activity?
You wouldn't set the notification if the user does not open the activity. Your app will only run when the user lets you run. If the user chooses not to start your app, or if the user chooses to "Force Stop" your app from within Settings, your manifest-registered receiver will not receive broadcasts.

Android Widget: Show configuration activity before widget is added to the screen

I have an Android Widget that uses web services to retrieve and display the data on the widget. The widget has a configuration activity that extends PreferenceActivity. The configuration activity starts up as soon as the widget is installed, which is the desired behavior for this widget.
The problem is, whenever a widget is added to the home screen, the widget attempts to update iteself before the configuration activity is started/completed which may potentially lead to a long delay (several seconds). The configuration activity should occur before the widget attempts to update itself anytime a new widget is added.
Here is the sequence of events that I'm seeing in LogCat when a widget is added:
Widget.onRecive: action = APPWIDGET_ENABLED
Widget.onEnabled
Widget.onReceive: action = APPWIDGET_UPDATE
Widget.onUpdate: Widget Service is started.
WidgetService.onStartCommand: Potentially long running work which will delay the configuration activity from being immediately shown.
WidgetConfiguration.onCreate
Widget.onReceive: action = APPWIDGET_UPDATE
Widget.onUpdate: Widget Service is started again
WidgetService.onStartCommand: Potentially long running work is performed again.
What's happening is that when a widget is added, the service will start up before the configuration view has been shown.
Manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="xxx.xxx.xxxwidget"
android:versionCode="1"
android:versionName="#string/app_version" >
<uses-sdk android:minSdkVersion="8" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:debuggable="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<receiver android:name="xxxWidget" >
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
<meta-data
android:name="android.appwidget.provider"
android:resource="#xml/widget_info" />
</receiver>
<activity android:name="xxxWidgetConfigure" >
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_CONFIGURE" />
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:name="xxxWidgetService" />
</application>
</manifest>
Question
Is there a way to force the configuration activity to be shown before the system attempts to add the widget to the home screen?
From android documentation:
http://developer.android.com/guide/topics/appwidgets/index.html#Configuring
The onUpdate() method will not be called when the App Widget is created (the system will not send the ACTION_APPWIDGET_UPDATE broadcast when a configuration Activity is launched). It is the responsibility of the configuration Activity to request an update from the AppWidgetManager when the App Widget is first created. However, onUpdate() will be called for subsequent updates—it is only skipped the first time.
HOWEVER, this does not seem to be correct!
What I did was adding a boolean to SharedPreferences which tells me if this widgetId has been through configuration. If not skip this update. Implement this in your AppWidgetProvider class' onUpdate method.
Declare ActivityConfig in manifest:
<activity
android:name="com.zoostudio.moneylover.widget.ActivityWidgetConfig"
android:label="Hello Widget Config">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_CONFIGURE" />
</intent-filter>
</activity>
With update widget class:
public abstract class SampleWiget extends AppWidgetProvider {
}
follow android developer widget support to understand it.

Why its my widget updating on the configuration activity creation?

i have set it to update each 12 hours :
android:updatePeriodMillis="43200000"
then in the manifest I have this:
<application android:icon="#drawable/icon" android:label="#string/app_name">
<!--
*************************************************************************************************
* Provider Configure Activity
*************************************************************************************************
-->
<activity android:name=".ConfiguratorActivity"
android:label="Configure Widget"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_CONFIGURE" />
</intent-filter>
</activity>
<!--
*************************************************************************************************
* Widget Provider Receiver
*************************************************************************************************
-->
<receiver android:name=".WidgetProvider">
<meta-data android:name="android.appwidget.provider"
android:resource="#xml/widget_provider" />
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
<service android:name=".AppWidget$UpdateService" />
</receiver>
</application>
however the application keep updating each time I create the widget itself when i start the configuration activity but it does not update when i click the ok button wich its the metod that have the forcing widget instructions =/
Widgets always get updated when you create them so that you can prepare the proper look. This is a good thing; otherwise your initial layout (as defined in the xml) would be displayed until it finally refreshes after 12 hours. If you don't need that you have to detect that it's the first refresh (write a flag to shared prefs) and then ignore this one.
Button: how did you connect the button to force a refresh?
Since Donut (Android 1.6) the minimum & maximum time to update the widget is 30 min, mainly to avoid your battery will be consumed shortly.
Android guys have to change their documentation:
https://developer.android.com/reference/android/appwidget/AppWidgetProviderInfo.html#updatePeriodMillis

Android Activity order

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="muazam.multiplication.one"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="3" />
<application android:icon="#drawable/icon" android:label="#string/app_name">
<activity android:label="#string/app_name" android:name=".multiplication">
<intent-filter android:priority="1">
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:label="#string/app_name" android:name=".splash">
<intent-filter android:priority="3">
<action android:name="android.intent.action.CLEARSCREEN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:label="#string/app_name" android:name=".Menu">
<intent-filter android:priority="2">
<action android:name="muazam.multiplication.one.Play" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
I want it to start with the .splash class first, and then .Menu class.
As you see I have put android:priority on them, but it seem to do nothing.
Anyone know how to solve this problem? Thanks.
I want it to start with the .splash class first
That has no meaning in Android.
If you meant to say "I want the .splash class to be what launches when the icon in the home screen launcher is clicked", then you need to get rid of the .splash class' current <intent-filter> (which is simply wrong) and move your MAIN/LAUNCHER <intent-filter> from the .multiplication class to the .splash class.
While you are at it, please get rid of the android:priority attributes (which are not used here) and your Play/DEFAULT <intent-filter> (which you really should not need, unless you plan on third-party apps starting up that activity directly).
and then .Menu class
You do this in Java code with startActivity().
As you see I have put android:priority on them, but it seem to do nothing.
Of course. There is no android:priority attribute for the <activity> element, as you can see in the documentation.
Activities aren't run automatically like a 'slide show' (although you could write your own code that way if you really wanted to).
The android:priority attribute is used for an entirely different purpose (from the docs for <intent-filter>...
It provides information about how able
an activity is to respond to an intent
that matches the filter, relative to
other activities that could also
respond to the intent. When an intent
could be handled by multiple
activities with different priorities,
Android will consider only those with
higher priority values as potential
targets for the intent.
In other word, if you have two activities each having an intent filter with the same action and category, then any Intent sent (from a 3rd party app) with those action/category details, will be passed first to the Activity whose intent filter has the highest priority.
This has nothing to do with how an app (and its activities) behave internally at runtime.

Categories

Resources