0

How do i call the function from inside onCreate()...I want to call CreateSharedactionprovider() from oncreate() but the app crashes...Am i not calling the function correctly or missing some arguements

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_camera);           
    // Show the Up button in the action bar.
    setupActionBar();

    CreateSharedactionprovider();
}

@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
public boolean CreateSharedactionprovider(Menu menu){
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        // Locate MenuItem with ShareActionProvider
         MenuItem item = menu.findItem(R.id.menu_share);
         // Fetch and store ShareActionProvider
         mShareActionProvider = (ShareActionProvider) item.getActionProvider();
         doShare();
    }
    return true;
}
user2429689
  • 149
  • 1
  • 3
  • 8

1 Answers1

2

CreateSharedActionprovider takes a Menu as argument, but you're calling it without any arguments. Looks like your Menu is null and you are trying to call findItem on it.

  • I tried using Menu as an arguement too but still nothing....Could you tell me how to do it – user2429689 Jul 14 '13 at 21:19
  • You need to create a menu object and pass it in from onCreate(). http://developer.android.com/guide/topics/ui/menus.html has a nice overview. –  Jul 14 '13 at 21:26
  • I read it...Actually the app use camera via Intent and when user takes picture and return to UI of my app I want that shareactionprovider should be available so obviously i want it to be called from onCreate()...How to call the method CreateSharedActionprovider()..Could you give a bit of code please – user2429689 Jul 15 '13 at 19:31
  • I'm sorry, I'm confused. This has nothing to do with the camera. On initialization, in onCreate, you need to instantiate your menu. Then you can pass it to CreatedSharedActionprovider. http://developer.android.com/guide/topics/ui/menus.html is about as clear as it gets. –  Jul 15 '13 at 19:41