I'm actually trying to use the built-in search interface of Android, but I have some issues when I try to pass data with the search query.
Here is a brief explanation : I have an object in a first Activity (FirstActivity) called "Category" which implements Serializable (I already pass it successfuly between Activities) and I want to perform a search related to that category, and display the results in a second Activity (SecondActivity).
So, in FirstActivity I override the onSearchRequest method :
#Override
public boolean onSearchRequested() {
Bundle appData = new Bundle();
appData.putSerializable("category", _currentCategory);
Log.d(Utils.LOG_TAG, "Bundle : "+appData.keySet());
startSearch(null, false, appData, false);
return true;
}
And in SecondActivity, I try to get this Bundle :
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
...
handleIntent(getIntent());
}
private void handleIntent(Intent intent){
Bundle appData = intent.getBundleExtra(SearchManager.APP_DATA);
if(appData == null) Log.d(Utils.LOG_TAG, "appData == null");
Log.d(Utils.LOG_TAG, "Extras : "+intent.getExtras().keySet());
}
Problem is that appData seems to be equals to null everytime. Here is the logcat output :
Bundle : [category]
appData == null
Extras : [query, user_query]
I tried to add some other objects into the Bundle (Booleans, etc...) but it doesn't change anything at all and I keep having a null appData.
I had problems figuring this out as well, and the examples I found didn't really help. A lot of them suggested overriding onSearchRequested(), but that actually doesn't work for SearchWidget. I ended up using the following (from danada) as a solution, since it seemed much simpler for me than setting up the OnQueryTextListener. I just overrode startActivity (in the first, search Activity) like so:
#Override
public void startActivity(Intent intent) {
//check if search intent
if(Intent.ACTION_SEARCH.equals(intent.getAction())) {
intent.putExtra("KEY", "VALUE");
}
super.startActivity(intent);
}
Then in the second, searchable Activity, I pulled out the info like so (called from onCreate() or from overriding onNewIntent() (if using singleTop)):
private void handleIntent(Intent intent){
if(Intent.ACTION_SEARCH.equals(intent.getAction())){
mSearchedQuery = intent.getStringExtra(SearchManager.QUERY);
mExtraData = intent.getStringExtra("KEY");
}
Simple, and worked like a charm! Check the link to the article above if you would like a little more explanation about it.
If you're using SearchView, it will not send your appData. Instead, consider using OnQueryTextListener. For example:
...
#Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.your-menu-id, menu);
/*
* Get the SearchView and set the searchable configuration.
*/
SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
SearchView searchView = (SearchView) menu.findItem(R.id.your-search-menuitem-id)
.getActionView();
searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
/*
* Set query text listener here.
*/
searchView.setOnQueryTextListener(mSearchViewOnQueryTextListener);
return true;
}// onCreateOptionsMenu()
...
private final SearchView.OnQueryTextListener mSearchViewOnQueryTextListener = new SearchView.OnQueryTextListener() {
#Override
public boolean onQueryTextSubmit(String query) {
/*
* You don't need to deal with "appData", because you already
* have the search query here.
*/
// Tell the SearchView that we handled the query.
return true;
}// onQueryTextSubmit()
#Override
public boolean onQueryTextChange(String newText) {
// TODO Auto-generated method stub
return false;
}// onQueryTextChange()
};// mSearchViewOnQueryTextListener
Note: You still need to keep the old way (using appData inside onSearchRequested()). In your onCreate(), if the extra for SearchManager.APP_DATA is null, that means you already handled the search query in the listener.
Conclusion:
If the SearchView is inactive, and you invoke it via onSearchRequested(), this will happen: onSearchRequested() >> onCreate() (ACTION_SEARCH contains SearchManager.APP_DATA).
If the SearchView is active, the user types and submits search, this will happen: SearchView.OnQueryTextListener.onQueryTextSubmit() >> onCreate() (ACTION_SEARCH without SearchManager.APP_DATA).
While putting data and retrieving it you are using two different keys. while putting you are using "category" and while retrieving you are using SearchManager.APP_DATA instead of using "category"
Try with
Bundle appData = intent.getBundleExtra("category");
Thanks
Deepak
In your example, you are asking for the keyset on the original intent object, and not the Bundle containing your appData. Here is an example that should work:
private void handleIntent(Intent intent){
final Bundle appData = intent.getBundleExtra(SearchManager.APP_DATA);
for (String key : appData.keySet()) {
Log.d(TAG, "key="+appData.getString(key));
}
}
Related
I have an OverviewActivity that contains a listview. When an item is selected, an intent is created to move to the DetailActivity and I pass an int with it.
This int is assigned to a private variable and is used to query the database.
DetailActivity code:
private int mIssueId;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_issue_detail);
mIssueId = getIntent().getIntExtra(IssueOverviewFragment.INTENT_ISSUE_ID, -1);
...
}
In the DetailActivity I can go to a GraphActivity. But when I press the upButton in the GraphActivity, the application crashes because the variable became -1 in the DetailActivity (and the database can thus not be queried properly).
The hierarchy is:
OverviewActivity -> DetailActivity -> GraphActivity
GraphActivity code:
protected void onCreate( Bundle savedInstanceState )
{
super.onCreate( savedInstanceState );
setContentView( R.layout.activity_graph );
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
...
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main_detail, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_logout: {
Utility.redirectToLogin(this);
break;
}
case android.R.id.home:
NavUtils.navigateUpFromSameTask(this);
return true;
}
return super.onOptionsItemSelected(item);
}
How do I retain the values of my mIssueId attribute in the DetailActivity?
The Intent intends to pass information between activities. When Activity1 pass control to Activity2 mostly related to the behavior of the activity.
If you have information you need to share across a complex hierarchy or to be available for your entire app, you can choice between Shared Preferences if you need persistence or use a Singleton class if the data only will be needed while the app is running.
This is a sample for a Singleton class keeping information to available to the entire app:
public class AppData {
private static AppData ourInstance = new AppData ();
public int score;
public static AppData getInstance () {
return ourInstance;
}
}
And how to access it:
AppData.getInstance().score = 100;
Hope it helps.
It looks like you are getting as a default value because there was an issue getting the intent in DetailActivity. You could try breaking up your request a little with
mIssueId = getIntent().getExtras().getInt();
But I think the issue is probably with how you are putting the int into the intent.
It should look something like
Intent intent = new Intent(context, DetailActivity.class);
intent.putExtra(IssueOverviewFragment.INTENT_ISSUE_ID, mIssueId);
startActivity(intent);
I have a Fragment that contains a SearchView. This fragment is include in my HomeActivity and in my SearchResultsActivity.
When the user uses the SearchView in HomeActivity to perform a search, they are shown the results in SearchResultsActivity.
I am trying to make it so the when the user enters a query into the SearchView on HomeActivity, their query String is remembered by the SearchView on the SearchResultsActivity.
I have tried all of the suggestions for this similar issue, but (along with a lot of other developers) the only solution that seems to work does not seem an adequate one - that is, saving the query in a static String in the Fragment class.
Here is my code which shows this approach...
`public class ProductSearchViewFragment extends Fragment {
private static final String LOG_TAG = ProductSearchViewFragment.class.getSimpleName();
private static final String KEY_QUERY = "query";
private static String mQuery = null;
public ProductSearchViewFragment() {
setArguments(new Bundle());
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_product_search_view, container, false);
}
#Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
/*
* Populate the searchView if there is a previous query
*/
SearchView searchView = (SearchView)getView().findViewById(R.id.searchView);
if (mQuery != null) {
Log.d(LOG_TAG, "######################### Setting searchView query from static String: " + mQuery);
searchView.setQuery(mQuery, false);
}
else {
Bundle mySavedInstanceState = getArguments();
String query = mySavedInstanceState.getString(KEY_QUERY);
if (query != null) {
// THIS CONDITION IS NEVER MET. I.E., query IS ALWAYS NULL
Log.d(LOG_TAG, "######################### Setting searchView query from bundle arguments: " + query);
searchView.setQuery(query, false);
}
else {
Log.d(LOG_TAG, "######################### Not setting searchView query.");
}
}
}
/*
* Unfortunately, onSaveInstanceState(Bundle outState) is not called,
* so attempt to save the query in our own arguments bundle.
*
*/
#Override
public void onPause() {
super.onPause();
SearchView searchView = (SearchView)getView().findViewById(R.id.searchView);
// Save to static field
mQuery = searchView.getQuery().toString();
// Save to arguments bundle
getArguments().putString(KEY_QUERY, mQuery);
Log.d(LOG_TAG, "#################### saved query: " + mQuery);
}
}`
...I think there must be a better way though than using a static String like this. Please, what is it?
As you'll see from the code, I have tried saving the query in setArguments() but it is never retrieved.
I've spent some time looking through the Android docs too, which suggests using onSaveInstanceState(), but that is not called unless the HomeActivity is destroyed (which does not happen and neither do I want to force it).
If I'm reading your question right, it sounds like you have two different instances of the ProductSearchViewFragment -- on on your "home" screen, and one on your "search results" screen. So on your home screen it creates the fragment when the activity is created, and destroys it when the activity is destroyed. Then on the search results activity a new instance of that fragment is created (and destroyed when the activity is destroyed). So arguments set on one instance won't automatically carry over to a separate instance.
My recommendation would be that when the user hits the "search" button on your home activity, you pass the search query from the fragment to the home activity. Then, when the home activity creates an instance of the search results activity, it can pass along an extra in the launch intent specifying the search string, and then the search results activity can use it in the fragment arguments when creating the search fragment.
I have ListActivty onCreate() where a list adapter is set with a cursor object holding all data within a database.
I have a search method in this ListActivity that calls a method in another database activity to retrieve a Cursor from a search, and returns the cursor to my ListActivity.
However after this method is called the ListActivty onCreate() is called again, where the the original list adapter with all data is called again, therefore I can never see the search results when i try to set the adapter with search cursor.
I have tried setting a boolean flag fro when savedInstance != null to set the correct search adapter but the savedInstance ALWAYS remains null......
So my question what is actually happening to the activity when the onCreate() is called twice?
EDIT: Added code
onCreate() I set the list apdter
public class ViewListOfTests extends ListActivity implements SearchView.OnQueryTextListener, SearchView.OnCloseListener{.....
this.setContentView(R.layout.list_activity);
// Associate searchable configuration with the SearchView
searchView = (SearchView) findViewById(R.id.search);
searchView.setIconifiedByDefault(false);
searchView.setOnQueryTextListener(this);
searchView.setOnCloseListener( this);
SearchManager searchManager =
(SearchManager) getSystemService(Context.SEARCH_SERVICE);
//SearchView searchView =(SearchView) menu.findItem(R.id.search).getActionView();
searchView.setSearchableInfo(
searchManager.getSearchableInfo(getComponentName()));
//(SearchView) this.findViewById(id) menu.findItem(R.id.search).getActionView();
/*call the aysnch inner class to load cursor form Db and set teh customer adter to this list view
*off the main UI thread, cast to type (getCursor)
*Asynch class does not have a constructor in this case
**/
if(savedInstanceState!=null){
//getCursorAysnch = (getCursor) new getCursor().execute();
searchPerformed=true;
}
//getCursorAysnch = (getCursor) new getCursor().execute();
try{
noOftimesOnCreateCalled = savedInstanceState.getInt("MyInt");
searchPerformed = savedInstanceState.getBoolean("MyBoolean");
}catch(Exception e){
e.printStackTrace();
Log.d("VIEWLISTTESTS", "noOFTOMESONCREATECALLED NOT CALLED");
}
if (noOftimesOnCreateCalled>0){
this.setListAdapter(searchAdapter);
Log.d("VIEWLISTOFDIVES", "IN ONCTREATE SERACHPERFOMED + TRUE");
}else if(noOftimesOnCreateCalled==0){
getCursorAysnch = (getCursor) new getCursor().execute();
Log.d("VIEWLISTOFDIVES", "IN ONCTREATE SERACHPERFOMED + FALSE");
noOftimesOnCreateCalled++;
}
I get the search query fem a searchView widget and call the following methow with the query, after this method the oCreate() is be called again...
#Override
public boolean onQueryTextChange(String newText) {
// TODO Auto-generated method stub
//handleIntent(intent);
Log.d("LIST ACTIVITY SEARCH", "onQueryTextCahanged called: "+ newText);
data = new database(this);
Cursor c = data.getWordMatches(newText, null);
Log.d("LISTACTIVITY", "CURSOR QUERY ROWS/COLS = "+ c.getCount()+" "+c.getColumnCount());
//now set bind cursor data to list view using custim ItemAdpter class
//ItemAdapter newAdapter = new ItemAdapter(ViewListOfTests.this, c);
//newAdapter.notifyDataSetChanged();
//ViewListOfTests.this.setListAdapter(newAdapter);
searchAdapter= new ItemAdapter(this, c);
//this.setListAdapter(searchAdapter);
searchPerformed=true;
return false;
}
Although savediNstanceState always remains nul I try to saved variables here:
#Override
public void onSaveInstanceState(Bundle savedInstanceState) {
super.onSaveInstanceState(savedInstanceState);
// Save UI state changes to the savedInstanceState.
// This bundle will be passed to onCreate if the process is
// killed and restarted ie when we go ot ItemAdter to craete a new adpter with serach
//savedInstanceState.putBoolean(key, false)
savedInstanceState.putBoolean("MyBoolean", true);
savedInstanceState.putDouble("myDouble", 1.9);
savedInstanceState.putInt("MyInt", 1);
savedInstanceState.putString("MyString", "Welcome back to Android");
// etc.
}
#Override
public void onRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
// Restore UI state from the savedInstanceState.
// This bundle has also been passed to onCreate.
searchPerformed = savedInstanceState.getBoolean("MyBoolean");
double myDouble = savedInstanceState.getDouble("myDouble");
noOftimesOnCreateCalled = savedInstanceState.getInt("MyInt");
String myString = savedInstanceState.getString("MyString");
}
In order for onCreate()'s savedInstanceState to be non-null, you have to provide Android with the saved state when Android forces the Activity to exit.
To do this, you must override the void onSaveInstanceState(Bundle savedInstanceState) method and fill in the passed-in savedInstanceState Bundle with whatever state you want.
Issue was I had some code to configure the searchable widget with a ACTION_SERACH intent when user submitted query :
#Override
protected void onNewIntent(Intent intent) {
// call handleIntent from here to handle the query from serah widget
super.onNewIntent(intent);
handleIntent(intent);
}//end onNewIntent
// Associate searchable configuration with the SearchView
SearchManager searchManager =
(SearchManager) getSystemService(Context.SEARCH_SERVICE);
SearchView searchView =
(SearchView) menu.findItem(R.id.search).getActionView();
searchView.setSearchableInfo(
searchManager.getSearchableInfo(getComponentName()));
I had forgotten to delete this code as wasn't aiming to configure search view with a ACTION_SEARCH intent, but I believe this intent was called and then calling the onCreate() again.
My problem is in understanding how to correctly use intents. After googling and reading all the documentations and articles on this topic, I still cannot sort out my problem. I have two activities: "Searchable" and "ActivityWordInfo". The "Searchable" activity searches a word in the database, and displays search results or suggestions. After the user cliks one of the search results, "ActivityWordInfo" activity is launched and diplays the word definition. Here is some part of the code:
Searchable:
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.search);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
// Get the intent, verify the action and get the query
if( savedInstanceState != null ){
//the application is being reloaded
query = savedInstanceState.getString("searchedWord");
doMySearch(query); //does the search in the database
}else{
Intent intent = getIntent();
if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
query = intent.getStringExtra(SearchManager.QUERY);
doMySearch(query);
}
}
}
#Override
public void onSaveInstanceState(Bundle savedInstanceState){
super.onSaveInstanceState(savedInstanceState);
savedInstanceState.putString("searchedWord", query);
//saves the searched word if this activity is killed
}
#Override
public void onClick(View v) { //when one of the search results is clicked
int wordID = (Integer) v.getTag();
Intent intent = new Intent(Searchable.this, ActivityWordInfo.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP|Intent.FLAG_ACTIVITY_SINGLE_TOP);
Bundle b = new Bundle();
b.putInt("key", wordID);
b.putInt("calling_activity", callingActivityId);
intent.putExtras(b);
startActivity(intent);
}
ActivityWordInfo:
public void onCreate(Bundle savedInstanceState) {
...
Bundle b = getIntent().getExtras();
current_word_id = b.getInt("key", 0);
callingActivityId = b.getInt("calling_activity", 0);
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
switch(callingActivityId){
case 3: //which is the ID of Searchable activity
Intent intent3 = new Intent(ActivityWordInfo.this, Searchable.class);
intent3.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP|Intent.FLAG_ACTIVITY_SINGLE_TOP);
startActivity(intent3);
break;
}
break;
}
When the user is in ActivityWordInfo and navigates up, I expect to go to Searchable activity, which should have saved its instance state (the list of results should be still there). What in reality happens:
-The word typed by the user is assigned to 'query' variable and then the results and suggestions are displayed in "Searchable"
-the user clicks one of the words and "ActivityWordInfo" is created
-then, when the user navigates up, the onSaveInstanceState is called for the "Searchable" activity, then it is destryed and created. The result is an empty layout :(
I cannot understand why "Searchable" is destroyed and then created! This only happens in Android 4.2 and not in lower APIs (in 2.3.3 worked perfectly as I expected). Is there any difference in the activity lifecycle in JellyBean?
Note: I cannot use the parentActivity attribute in the manifest since the ActivityWordInfo is called by multiple parents.
The behavior of "up" navigation changed between 2.3 and 4.0. I suggest you look at the topic "Tasks and Back Stack" at developer.android.com.
The new ShareActionProvider available in Android 4.0 (or in earlier versions if you're using ActionBarSherlock) has a feature where the last used item is displayed in the action bar. Is there anyway to turn this off?
For me, the best solution for avoid the history icon is don't use ShareActionProvider, instead of it, create it as any other action:
<item
android:id="#+id/menu_action_share"
android:showAsAction="ifRoom"
android:icon="#drawable/ic_action_share"
android:title="#string/share"/>
at the menu/activity_actions.xml put a item with the ic_action_share icon...
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_actions, menu);
return super.onCreateOptionsMenu(menu);
}
Inflate the menu normally...
private void actionShare(){
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("text/plain");
i.putExtra(Intent.EXTRA_SUBJECT, "my string");
i.putExtra(Intent.EXTRA_TEXT, "another string");
startActivity(i);
//Or like above will always display the chooser
//startActivity(Intent.createChooser(i, getResources().getText(R.string.share)));
}
Create a method with an ACTION_SEND intent
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.menu_item_share:
actionShare();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
And finally call to this method from onOptionsItemSelected
more info ->Sending Simple Data to Other Apps
Start the share activity by yourself:
shareActionProvider.setShareIntent(intent);
shareActionProvider.setOnShareTargetSelectedListener(this);
#Override
public boolean onShareTargetSelected(ShareActionProvider source, Intent intent) {
// start activity ourself to prevent search history
context.startActivity(intent);
return true;
}
Then the ShareActionProvider will not add the chosen activity to the share history.
I created my own version of the ShareActionProvider (and supporting classes), you can copy them into your project (https://gist.github.com/saulpower/10557956). This not only adds the ability to turn off history, but also to filter the apps you would like to share with (if you know the package name).
private final String[] INTENT_FILTER = new String[] {
"com.twitter.android",
"com.facebook.katana"
};
#Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.journal_entry_menu, menu);
// Set up ShareActionProvider's default share intent
MenuItem shareItem = menu.findItem(R.id.action_share);
if (shareItem instanceof SupportMenuItem) {
mShareActionProvider = new ShareActionProvider(this);
mShareActionProvider.setShareIntent(ShareUtils.share(mJournalEntry));
mShareActionProvider.setIntentFilter(Arrays.asList(INTENT_FILTER));
mShareActionProvider.setShowHistory(false);
((SupportMenuItem) shareItem).setSupportActionProvider(mShareActionProvider);
}
return super.onCreateOptionsMenu(menu);
}
There is no API to do this. However, the class is really simple and you could very easily create your own version of ShareActionProvider that did not keep a history. You would just have to determine the sort order of the possible targets using some other means of ordering (e.g., alphabetically).
Point of clarification: It's not the "last used", it's "most often used", across a sliding window period of time.
If you prefer not to use history, then before creating your views, call
yourShareActionProvider.setShareHistoryFileName(null);
Description of this method, from the official docs (emphasis mine):
Sets the file name of a file for persisting the share history which history will be used for ordering share targets. This file will be used for all view created by onCreateActionView(). Defaults to DEFAULT_SHARE_HISTORY_FILE_NAME. Set to null if share history should not be persisted between sessions.
EDIT: I should clarify — The "most often used" item won't show up if there's no history, so this is currently the only way of removing that button.
Although It's been 2 years ago today but I'd like to share my experience as I made a custom ShareActionProvider class and add this line chooserView.getDataModel().setHistoryMaxSize(0); inside onCreateActionView() which did all the magic for me ! .. I tested it on Lollipop device and on API 16 emulator device and it works perfectly. here is my custom class :
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.support.v7.internal.widget.ActivityChooserView;
import android.support.v7.widget.ShareActionProvider;
import android.view.View;
public class MyShareActionProvider extends ShareActionProvider {
/**
* Creates a new instance.
*
* #param context Context for accessing resources.
*/
public MyShareActionProvider(Context context) {
super(context);
}
#Override
public View onCreateActionView() {
ActivityChooserView chooserView = (ActivityChooserView) super.onCreateActionView();
Drawable icon;
if (Build.VERSION.SDK_INT >= 21) {
icon = getContext().getDrawable(R.drawable.share_icon);
}else{
icon = getContext().getResources().getDrawable(R.drawable.share_icon);
}
chooserView.setExpandActivityOverflowButtonDrawable(icon);
chooserView.getDataModel().setHistoryMaxSize(0);
return chooserView;
}
}
add the code like this:
private void addShareSelectedListener() {
if (null == mShareActionProvider) return;
OnShareTargetSelectedListener listener = new OnShareTargetSelectedListener() {
public boolean onShareTargetSelected(ShareActionProvider source, Intent intent) {
mContex.startActivity(intent);
return true;
}
};
//Set to null if share history should not be persisted between sessions.
mShareActionProvider.setShareHistoryFileName(null);
mShareActionProvider.setOnShareTargetSelectedListener(listener);
}
getSupportMenuInflater().inflate(R.menu.share_action_provider, menu);
// Set file with share history to the provider and set the share intent.
MenuItem actionItem = menu.findItem(R.id.menu_item_share_action_provider_action_bar);
ShareActionProvider actionProvider = (ShareActionProvider) actionItem.getActionProvider();
***actionProvider.setShareHistoryFileName(null);
OnShareTargetSelectedListener listener = new OnShareTargetSelectedListener() {
public boolean onShareTargetSelected(ShareActionProvider source, Intent intent) {
startActivity(intent);
return true;
}
};
actionProvider.setOnShareTargetSelectedListener(listener);***