IT. Expert System.

Android Reference



Class ActivityChooserModel

  • public class ActivityChooserModel
    extends DataSetObservable

    This class represents a data model for choosing a component for handing a given Intent. The model is responsible for querying the system for activities that can handle the given intent and order found activities based on historical data of previous choices. The historical data is stored in an application private file. If a client does not want to have persistent choice history the file can be omitted, thus the activities will be ordered based on historical usage for the current session.

    For each backing history file there is a singleton instance of this class. Thus, several clients that specify the same history file will share the same model. Note that if multiple clients are sharing the same model they should implement semantically equivalent functionality since setting the model intent will change the found activities and they may be inconsistent with the functionality of some of the clients. For example, choosing a share activity can be implemented by a single backing model and two different views for performing the selection. If however, one of the views is used for sharing but the other for importing, for example, then each view should be backed by a separate model.

    The way clients interact with this class is as follows:

      // Get a model and set it to a couple of clients with semantically similar function.
      ActivityChooserModel dataModel =
          ActivityChooserModel.get(context, "task_specific_history_file_name.xml");
      ActivityChooserModelClient modelClient1 = getActivityChooserModelClient1();
      ActivityChooserModelClient modelClient2 = getActivityChooserModelClient2();
      // Set an intent to choose a an activity for.

    Note: This class is thread safe.

    • Field Detail


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

        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.

        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.
        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.

        intent - The intent.
      • getIntent

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

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

        public int getActivityIndex(ResolveInfo activity)
        Gets the index of a the given activity.
        activity - The activity index.
        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.

        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.
        The default activity, null id not activities.
        See Also:
      • 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.
        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.

        historyMaxSize - The max history size.
      • getHistoryMaxSize

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

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

        protected void finalize()
                         throws Throwable
        Description copied from class: Object
        Invoked when the garbage collector has detected that this instance is no longer reachable. The default implementation does nothing, but this method can be overridden to free resources.

        Note that objects that override finalize are significantly more expensive than objects that don't. Finalizers may be run a long time after the object is no longer reachable, depending on memory pressure, so it's a bad idea to rely on them for cleanup. Note also that finalizers are run on a single VM-wide finalizer thread, so doing blocking work in a finalizer is a bad idea. A finalizer is usually only necessary for a class that has a native peer and needs to call a native method to destroy that peer. Even then, it's better to provide an explicit close method (and implement Closeable), and insist that callers manually dispose of instances. This works well for something like files, but less well for something like a BigInteger where typical calling code would have to deal with lots of temporaries. Unfortunately, code that creates lots of temporaries is the worst kind of code from the point of view of the single finalizer thread.

        If you must use finalizers, consider at least providing your own ReferenceQueue and having your own thread process that queue.

        Unlike constructors, finalizers are not automatically chained. You are responsible for calling super.finalize() yourself.

        Uncaught exceptions thrown by finalizers are ignored and do not terminate the finalizer thread. See Effective Java Item 7, "Avoid finalizers" for more.

        finalize in class Object


Android Reference

Java basics

Java Enterprise Edition (EE)

Java Standard Edition (SE)





Java Script








Design patterns

RFC (standard status)

RFC (proposed standard status)

RFC (draft standard status)

RFC (informational status)

RFC (experimental status)

RFC (best current practice status)

RFC (historic status)

RFC (unknown status)

IT dictionary

All information of this service is derived from the free sources and is provided solely in the form of quotations. This service provides information and interfaces solely for the familiarization (not ownership) and under the "as is" condition.
Copyright 2016 © ELTASK.COM. All rights reserved.
Site is optimized for mobile devices.
Downloads: 63 / 159283099. Delta: 0.05652 с