Skip navigation links
android.widget

Class ActivityChooserModel

    • Field Detail

      • DEFAULT_HISTORY_FILE_NAME

        public static final String DEFAULT_HISTORY_FILE_NAME
        The default name of the choice history file.
        See Also:
        Constant Field Values
      • DEFAULT_HISTORY_MAX_LENGTH

        public static final int DEFAULT_HISTORY_MAX_LENGTH
        The default maximal length of the choice history.
        See Also:
        Constant Field Values
    • Method Detail

      • get

        public static ActivityChooserModel get(Context context,
                                               String historyFileName)
        Gets the data model backed by the contents of the provided file with historical data. Note that only one data model is backed by a given file, thus multiple calls with the same file name will return the same model instance. If no such instance is present it is created.

        Note: To use the default historical data file clients should explicitly pass as file name DEFAULT_HISTORY_FILE_NAME. If no persistence of the choice history is desired clients should pass null for the file name. In such case a new model is returned for each invocation.

        Always use difference historical data files for semantically different actions. For example, sharing is different from importing.

        Parameters:
        context - Context for loading resources.
        historyFileName - File name with choice history, null if the model should not be backed by a file. In this case the activities will be ordered only by data from the current session.
        Returns:
        The model.
      • setIntent

        public void setIntent(Intent intent)
        Sets an intent for which to choose a activity.

        Note: Clients must set only semantically similar intents for each data model.

        Parameters:
        intent - The intent.
      • getIntent

        public Intent getIntent()
        Gets the intent for which a activity is being chosen.
        Returns:
        The intent.
      • getActivityCount

        public int getActivityCount()
        Gets the number of activities that can handle the intent.
        Returns:
        The activity count.
        See Also:
        setIntent(Intent)
      • getActivityIndex

        public int getActivityIndex(ResolveInfo activity)
        Gets the index of a the given activity.
        Parameters:
        activity - The activity index.
        Returns:
        The index if found, -1 otherwise.
      • chooseActivity

        public Intent chooseActivity(int index)
        Chooses a activity to handle the current intent. This will result in adding a historical record for that action and construct intent with its component name set such that it can be immediately started by the client.

        Note: By calling this method the client guarantees that the returned intent will be started. This intent is returned to the client solely to let additional customization before the start.

        Returns:
        An Intent for launching the activity or null if the policy has consumed the intent or there is not current intent set via setIntent(Intent).
        See Also:
        ActivityChooserModel.HistoricalRecord, ActivityChooserModel.OnChooseActivityListener
      • getDefaultActivity

        public ResolveInfo getDefaultActivity()
        Gets the default activity, The default activity is defined as the one with highest rank i.e. the first one in the list of activities that can handle the intent.
        Returns:
        The default activity, null id not activities.
        See Also:
        getActivity(int)
      • setDefaultActivity

        public void setDefaultActivity(int index)
        Sets the default activity. The default activity is set by adding a historical record with weight high enough that this activity will become the highest ranked. Such a strategy guarantees that the default will eventually change if not used. Also the weight of the record for setting a default is inflated with a constant amount to guarantee that it will stay as default for awhile.
        Parameters:
        index - The index of the activity to set as default.
      • setHistoryMaxSize

        public void setHistoryMaxSize(int historyMaxSize)
        Sets the maximal size of the historical data. Defaults to DEFAULT_HISTORY_MAX_LENGTH

        Note: Setting this property will immediately enforce the specified max history size by dropping enough old historical records to enforce the desired size. Thus, any records that exceed the history size will be discarded and irreversibly lost.

        Parameters:
        historyMaxSize - The max history size.
      • getHistoryMaxSize

        public int getHistoryMaxSize()
        Gets the history max size.
        Returns:
        The history max size.
      • getHistorySize

        public int getHistorySize()
        Gets the history size.
        Returns:
        The history size.
      • finalize

        protected void finalize()
                         throws Throwable
        Description copied from class: Object
        Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. A subclass overrides the finalize method to dispose of system resources or to perform other cleanup.

        The general contract of finalize is that it is invoked if and when the JavaTM virtual machine has determined that there is no longer any means by which this object can be accessed by any thread that has not yet died, except as a result of an action taken by the finalization of some other object or class which is ready to be finalized. The finalize method may take any action, including making this object available again to other threads; the usual purpose of finalize, however, is to perform cleanup actions before the object is irrevocably discarded. For example, the finalize method for an object that represents an input/output connection might perform explicit I/O transactions to break the connection before the object is permanently discarded.

        The finalize method of class Object performs no special action; it simply returns normally. Subclasses of Object may override this definition.

        The Java programming language does not guarantee which thread will invoke the finalize method for any given object. It is guaranteed, however, that the thread that invokes finalize will not be holding any user-visible synchronization locks when finalize is invoked. If an uncaught exception is thrown by the finalize method, the exception is ignored and finalization of that object terminates.

        After the finalize method has been invoked for an object, no further action is taken until the Java virtual machine has again determined that there is no longer any means by which this object can be accessed by any thread that has not yet died, including possible actions by other objects or classes which are ready to be finalized, at which point the object may be discarded.

        The finalize method is never invoked more than once by a Java virtual machine for any given object.

        Any exception thrown by the finalize method causes the finalization of this object to be halted, but is otherwise ignored.

        Overrides:
        finalize in class Object
        Throws:
        Throwable - the Exception raised by this method