FirebaseListAdapter not firing populateView() - android

After finding some people saying that FirebaseRecyclerAdapters are broken inside of fragments (and trying for about 4 hours to get it to work before that), I decided to switch to a FirebaseListAdapter, as I found examples of that working inside of fragments. However, I'm having issues. The populateView() method never seems to be firing and I'm getting no errors. Here is my code for the fragment:
public class PasteFromFirebasePopup extends DialogFragment implements AdapterView.OnClickListener {
Activity activity;
private FirebaseListAdapter mFirebaseAdapter;
private DatabaseReference mClipboardHistoryReference;
private ListView mListView;
public PasteFromFirebasePopup() {}
#Override public View onCreateView(LayoutInflater inflater, #Nullable ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.clip_history_popup_list, container, false);
mListView = (ListView) rootView.findViewById(R.id.clipboardHistoryListView);
activity = getActivity();
mClipboardHistoryReference = FirebaseDatabase.getInstance().getReference(Constants.FIREBASE_CHILD_CLIPBOARD_HISTORY);
Log.d("clipboardRef", mClipboardHistoryReference.toString());
mFirebaseAdapter = new FirebaseListAdapter<FirebaseString>
(activity, FirebaseString.class, R.layout.clip_history_popup_item, mClipboardHistoryReference) {
TextView mTextView;
#Override protected void populateView(View v, FirebaseString model, int position) {
mTextView = (TextView) v.findViewById(R.id.clipboardHistoryTextView);
Log.d("model text", model.getText());
mTextView.setText(model.getText());
}
};
mListView.setAdapter(mFirebaseAdapter);
return rootView;
}
#Override public void onClick(View v) {}
#Override public void onDestroy() {
super.onDestroy();
mFirebaseAdapter.cleanup();
}
}
No matter what I try, the log inside of populateView() absolutely never fires. I have triple checked my reference, and there is indeed something in there (only one item at the moment, but as far as I can tell that shouldn't matter). Am I missing something? Does this not work inside of DialogFragments? If not, does anyone have a suggestion for a popup that can hold a FirebaseListAdapter/RecyclerAdapter successfully?
Any help is duly appreciated.
EDIT: my build.gradle (app) , as I think this may have something to do with it.
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
androidTestCompile('com.android.support.test:runner:0.3') {
exclude group: 'com.android.support', module: 'support-annotations'
}
compile 'com.squareup.okhttp3:okhttp:3.2.0'
compile 'com.github.smart-fun:XmlToJson:1.2.2'
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.android.support:design:25.3.1'
compile 'com.android.support:gridlayout-v7:25.3.1'
compile 'com.android.support:recyclerview-v7:25.3.1'
compile 'com.android.support:support-v4:25.3.1'
testCompile 'org.robolectric:robolectric:3.0'
testCompile 'org.robolectric:shadows-support-v4:3.0'
testCompile 'junit:junit:4.12'
compile 'com.google.firebase:firebase-database:11.0.0'
compile 'com.firebaseui:firebase-ui-database:1.2.0'
compile 'com.google.android.gms:play-services:11.0.0'
compile 'org.parceler:parceler-api:1.1.6'
annotationProcessor 'org.parceler:parceler:1.1.6'
compile 'com.jakewharton:butterknife:8.6.0'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.6.0'
}
apply plugin: 'com.google.gms.google-services'

Related

ViroCore: java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/vr/ndk/base/GvrLayout;

I have downloaded ViroCore lib the latest version (virocore-release-v_1_7_2.aar), then I added dependencies below to my build.gradle file
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:25.0.0'
implementation 'com.google.android.exoplayer:exoplayer:r2.2.0'
androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
testImplementation 'junit:junit:4.12'
implementation (name:'virocore-release-v_1_7_2', ext: 'aar')
implementation 'com.google.protobuf.nano:protobuf-javanano:3.0.0-alpha-7'
implementation 'com.amazonaws:aws-android-sdk-core:2.2.+'
implementation 'com.amazonaws:aws-android-sdk-ddb:2.2.+'
implementation 'com.amazonaws:aws-android-sdk-ddb-mapper:2.2.+'
implementation 'com.amazonaws:aws-android-sdk-cognito:2.2.+'
implementation 'com.amazonaws:aws-android-sdk-cognitoidentityprovider:2.2.+'}
and then wrote to my ViroActivity code below:
private ViroView createGVRView() {
return new ViroViewGVR(this, new ViroViewGVR.StartupListener() {
#Override
public void onSuccess() {
onRendererStart();
}
#Override
public void onFailure(ViroViewGVR.StartupError error, String errorMessage) {
onRendererFailed(error.toString(), errorMessage);
}
}, new Runnable() {
#Override
public void run() {
}
});
}
But when run the app, I always see next Exception:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.virosample.gvr.ovr, PID: 17304
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/vr/ndk/base/GvrLayout;
at com.viro.core.ViroViewGVR.init(ViroViewGVR.java:287)
at com.viro.core.ViroViewGVR.<init>(ViroViewGVR.java:211)
at com.example.panorama.ui.view.ViroActivityVR.createGVRView(ViroActivityVR.java:104)
at com.example.panorama.ui.view.ViroActivityVR.onCreate(ViroActivityVR.java:90)
...
Anyone knows how to resolve this exception?
I solved this issue. I added to my dependency just viro library, but I must add additionally both sdk-common.aar and core.aar which you can download at the official virocore site.

Greenrobot Android Eventbus - No option eventbusindex passed to annotation processor

I'm trying to set up a simple subscriber in my Android application using Greenrobot's Eventbus, but I am getting a gradle build error. I have shown my code below.
Event class
public final class OffersProcessedEvent {}
Base Fragment
public class BaseFragment extends Fragment {
private boolean registered;
#Override
public void onViewCreated(View view, #Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
EventBus.getDefault().register(this);
registered = true;
}
#Override
public void onResume() {
super.onResume();
if (!registered) {
EventBus.getDefault().register(this);
registered = true;
}
}
#Override
public void onPause() {
super.onPause();
EventBus.getDefault().unregister(this);
registered = false;
}
public AppCompatActivity getAppCompatActivity() {
return (AppCompatActivity) getActivity();
}
}
Event post'
EventBus.getDefault().post(new OffersProcessedEvent());
Subscribe code
#Subscribe
public void onMessageEvent(OffersProcessedEvent event){
*do whatever*
}
The following are my errors
Build Gradle Errors
Error:No option eventBusIndex passed to annotation processor
Error:Execution failed for task ':app:compileDebugJavaWithJavac'.
Compilation failed; see the compiler error output for details.
Gradle dependencies
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:26.+'
compile 'com.android.support:design:26.+'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
testCompile 'junit:junit:4.12'
compile 'com.facebook.android:facebook-android-sdk:4.5.0'
compile 'com.jakewharton:butterknife:8.6.0'
compile 'com.jakewharton:butterknife-compiler:8.6.0'
compile 'com.jakewharton:butterknife:8.7.0'
compile 'com.jakewharton:butterknife-compiler:8.7.0'
compile 'com.github.bumptech.glide:glide:3.5.2'
compile 'com.android.support:cardview-v7:26.0.0-alpha1'
compile 'com.google.code.gson:gson:2.8.1'
compile 'org.greenrobot:eventbus:3.0.0'
compile 'org.greenrobot:eventbus-annotation-processor:3.0.1'
}
apply plugin: 'kotlin-kapt' // ensure kapt plugin is applied
dependencies {
implementation 'org.greenrobot:eventbus:3.1.1'
kapt 'org.greenrobot:eventbus-annotation-processor:3.1.1'
}
kapt {
arguments {
arg('eventBusIndex', 'com.example.myapp.MyEventBusIndex')
}
}
Base on this link http://greenrobot.org/eventbus/documentation/faq/
This happens when you set up the build script, and you did not add any
annotations to your code yet. Without any #Subscribe annotations,
annotation processor for indexing will not be triggered to consume the
‘eventBusIndex’ option. So, just add some #Subscribe annotations and
you should be fine.
So you must add
#Subscribe
fun onEvent(event: SomeEvent) {
}
But is you steel getting Error:No option eventBusIndex passed to annotation processor
Add this to your app.gradle
If using annotationProcessor
defaultConfig {
//other code
javaCompileOptions {
annotationProcessorOptions {
arguments = [eventBusIndex: "com.example.myapp.MyEventBusIndex"]
}
}
}
If using kapt
dependencies {
//other codes
}
kapt {
arguments {
arg('eventBusIndex', 'com.example.myapp.MyEventBusIndex')
}
}
And if using android-apt
dependencies {
//other codes
}
apt {
arguments {
eventBusIndex "com.example.myapp.MyEventBusIndex"
}
}
And this file will be generate by EventBus
/** This class is generated by EventBus, do not edit. */
public class MyEventBusIndex implements SubscriberInfoIndex {
private static final Map<Class<?>, SubscriberInfo> SUBSCRIBER_INDEX;
static {
SUBSCRIBER_INDEX = new HashMap<Class<?>, SubscriberInfo>();
putIndex(new SimpleSubscriberInfo(MainActivity.class, true, new SubscriberMethodInfo[] {
new SubscriberMethodInfo("onBleClick", com.example.myapp.Events.BleClickListener.class),
}));
}
private static void putIndex(SubscriberInfo info) {
SUBSCRIBER_INDEX.put(info.getSubscriberClass(), info);
}
#Override
public SubscriberInfo getSubscriberInfo(Class<?> subscriberClass) {
SubscriberInfo info = SUBSCRIBER_INDEX.get(subscriberClass);
if (info != null) {
return info;
} else {
return null;
}
}
}
Hope it's help

NoSuchMethodError Neura

I found the example of auth in Neura, then created an activity and pasted this code:
public class NeuraActivity extends AppCompatActivity {
private NeuraApiClient mNeuraApiClient;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_neura);
Builder builder = new Builder(getApplicationContext());
mNeuraApiClient = builder.build();
mNeuraApiClient.setAppUid("APP_UID");
mNeuraApiClient.setAppSecret("APP_SECRET"); //here is my app secret, I dont want to show it
mNeuraApiClient.connect();
auth();
}
public void auth() {
mNeuraApiClient.authenticate(new AuthenticateCallback() {
#Override
public void onSuccess(AuthenticateData authenticateData) {
Log.i(getClass().getSimpleName(), "Successfully authenticate with neura. " +
"NeuraUserId = " + authenticateData.getNeuraUserId() + " " +
"AccessToken = " + authenticateData.getAccessToken());
//If you're using firebase for receiving the moment, make sure to call this method.
//Plus, make sure you've registered your firebase server key for your project in our dev site :
//https://dev.theneura.com/docs/guide/android/pushnotification
//If you're putting this code in an activity : ACTIVITY_CONTEXT = YourActivityName.this.
//If you're putting this code in an fragment : ACTIVITY_CONTEXT = getActivity()
mNeuraApiClient.registerFirebaseToken(NeuraActivity.this,
FirebaseInstanceId.getInstance().getToken());
ArrayList<EventDefinition> events = authenticateData.getEvents();
//Subscribe to the events you wish Neura to alert you :
for (int i = 0; i < events.size(); i++) {
mNeuraApiClient.subscribeToEvent(events.get(i).getName(),
"com.chopikus.schoolhelperse" + events.get(i).getName(),
new SubscriptionRequestCallbacks() {
#Override
public void onSuccess(String eventName, Bundle bundle, String s1) {
Log.i(getClass().getSimpleName(), "Successfully subscribed to event " + eventName);
}
#Override
public void onFailure(String eventName, Bundle bundle, int i) {
Log.e(getClass().getSimpleName(), "Failed to subscribe to event " + eventName);
}
});
}
}
#Override
public void onFailure(int i) {
Log.e(getClass().getSimpleName(), "Failed to authenticate with neura. "
+ "Reason : " + SDKUtils.errorCodeToString(i));
}
});
}
}
Here is my gradle dependencies:
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
// this line must be included to integrate with Firebase
compile 'com.google.firebase:firebase-core:11.0.1'
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:design:25.3.1'
compile 'com.google.firebase:firebase-auth:11.0.1'
compile 'com.google.firebase:firebase-storage:11.0.1'
compile 'com.google.firebase:firebase-database:11.0.1'
compile 'com.google.firebase:firebase-messaging:11.0.1'
compile 'org.apache.directory.studio:org.apache.commons.io:2.4'
compile 'com.koushikdutta.ion:ion:2.+'
compile 'com.github.barteksc:android-pdf-viewer:2.5.1'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.github.kenglxn.QRGen:android:2.2.0'
compile 'me.dm7.barcodescanner:zxing:1.9'
compile 'com.google.zxing:core:3.2.1'
compile 'com.dlazaro66.qrcodereaderview:qrcodereaderview:2.0.1'
compile 'com.afollestad.material-dialogs:core:0.9.4.5'
compile 'com.github.clans:fab:1.6.2'
compile 'com.google.android.gms:play-services-auth:11.0.1'
compile 'com.facebook.android:facebook-android-sdk:[4,5)'
compile 'com.github.chrisbanes:PhotoView:2.0.0'
compile 'me.grantland:autofittextview:0.2.+'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.theneura:android-sdk:+'
testCompile 'junit:junit:4.12'
}
And when I start activity I get the error:
java.lang.NoSuchMethodError: No static method zzw(Ljava/lang/Object;)Ljava/lang/Object; in class Lcom/google/android/gms/common/internal/zzac;
Please help me.
Add this in your gradle
compile "com.google.android.gms:play-services-base:+"
compile 'com.google.android.gms:play-services-location:+'
compile 'com.google.android.gms:play-services-maps:+'
I just added playservices-analytics,base, location, maps library and all is working.

Fcm token getting null

i have used following dependencies.
it gives me "Default FirebaseApp is not initialized in this process.Make sure to call FirebaseApp.initializeApp(Context) first."
dependencies
{
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2',
{
exclude group: 'com.android.support', module: 'support-annotations'
})
/*compile('org.apache.httpcomponents:httpcore:4.4.1') {
exclude group: 'org.apache.httpcomponents', module: 'httpclient'
}*/
/*Button*/
//Google Analytics
//Sweet Alert Dialog
compile('com.google.api-client:google-api-client-android:1.22.0')
compile('com.google.apis:google-api-services-script:v1-rev6-1.22.0') {
exclude group: 'org.apache.httpcomponents'
}
/*Button*/
//Google Analytics
//Sweet Alert Dialog
compile 'pub.devrel:easypermissions:0.1.5'
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:design:23.4.0'
compile 'com.github.markushi:circlebutton:1.1'
compile 'com.github.dmytrodanylyk.android-process-button:library:1.0.4'
compile 'cn.pedant.sweetalert:library:1.3'
compile 'me.spark:submitbutton:1.0.1'
compile 'com.android.support:support-v4:23.4.0'
compile 'com.google.firebase:firebase-messaging:9.8.0'
compile 'com.google.android.gms:play-services-auth:9.8.0'
compile 'com.google.android.gms:play-services-appindexing:9.8.0'
testCompile 'junit:junit:4.12'
compile files('libs/org.apache.http.legacy.jar')
}
This has little to do with your dependencies, you'll need to initialize Firebase before using it in your code.
So at the very beginning (Or at least before you make any references to Firebase) add the following:
FirebaseApp.initializeApp(getContext());
In Your Project gradle file put this dependancy
classpath 'com.google.gms:google-services:3.0.0'
and than your module gradle
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.google.firebase:firebase-messaging:10.0.1'
}
apply plugin: 'com.google.gms.google-services'
it Work for me.
Put this line at the bottom of your app build.gradle file (* last statement)
apply plugin: 'com.google.gms.google-services'
and also check if you are using this dependency in upper gradle file
dependencies {
classpath 'com.android.tools.build:gradle:1.5.0'
//classpath 'com.android.tools.build:gradle:2.0.0'
classpath 'com.google.gms:google-services:3.0.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
You have to initialize Firebase befor you use it and best place to initialize it in Application Class
public class App extends BaseApplication {
public static App _appContext = null;
public static final String TAG = App.class.getSimpleName();
#Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
#Override
public void onCreate() {
super.onCreate();
_appContext = this;
Firebase.setAndroidContext(getApplicationContext());
FirebaseApp.initializeApp(getContext());
}
}
And add it to mainifiest file Application Tag like
<application
android:name="your.path.to.App"
.
.>
Than try and let me know
You can try this
Remove:
Firebase.setAndroidContext(this);
FirebaseApp.initializeApp(this);
And put:
FirebaseDatabase database = FirebaseDatabase.getInstance();

Migrating from appcompat-v7:21.0.1 to appcompat-v7:23.1.1 now im sad

Migrating from appcompat-v7:21.0.1 to appcompat-v7:23.1.1 OnPrepareOptionsMenu is not called, now im sad.
Before I migrated the support library there was no issue at all. Then between 2-3 builds/runs(If i add code or add resources) menu suddenly disappears with no errors run-time nor compile time. I LOG onPrepareOptionsMenu calls and as expected it doesn't get called. I tried going back to 21.0.1 but i encountered much more fearsome issues. In-short I cannot go back.
What I always do is do
Build->Clean
And It would show my menu back again.
If this would be helpful I will post what I deem relevant:
dependencies {
// compile fileTree(dir: 'libs', include: ['*.jar'])
compile files('libs/mqttv3-1.0.0.jar')
compile 'com.github.traex.rippleeffect:library:1.3'
provided 'com.squareup.dagger:dagger-compiler:1.2.2'
compile('de.keyboardsurfer.android.widget:crouton:1.8.5#aar') {
// exclusion is not neccessary, but generally a good idea.
exclude group: 'com.google.android', module: 'support-v4'
}
// Google Activity Recognition
// Google Maps
// Google+'
// Google Account Login
dependencies {
compile('com.mapbox.mapboxsdk:mapbox-android-sdk:0.7.4#aar') {
transitive = true
}
}
testCompile 'org.mockito:mockito-core:1.9.5'
testCompile files('libs/dexmaker-mockito-1.0.jar')
testCompile files('libs/dexmaker-1.0.jar')
testCompile 'junit:junit:4.12'
testCompile('org.robolectric:robolectric:3.0') {
exclude group: 'commons-logging', module: 'commons-logging'
exclude group: 'org.apache.httpcomponents', module: 'httpclient'
}
testCompile 'com.squareup:fest-android:1.0.+'
testCompile 'org.robolectric:shadows-multidex:3.0'
compile('com.crashlytics.sdk.android:crashlytics:2.2.3#aar') {
transitive = true;
}
compile 'com.wdullaer:materialdatetimepicker:1.4.2'
debugCompile 'com.squareup.leakcanary:leakcanary-android:1.3.1'
releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.3.1'
compile 'com.andreabaccega:android-form-edittext:1.1.0#aar'
compile 'com.shehabic.droppy:Droppy:0.2.5.1#aar'
compile 'com.andreabaccega:android-form-edittext:1.1.0#aar'
compile 'com.github.gcacace:signature-pad:1.0.1'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:cardview-v7:23.1.1'
compile 'com.android.support:recyclerview-v7:23.1.1'
compile 'com.android.support:support-v4:23.1.1'
compile 'com.github.anrwatchdog:anrwatchdog:1.1.1'
compile 'com.android.support:multidex:1.0.1'
compile 'com.squareup.picasso:picasso:2.5.0'
compile 'com.jakewharton:butterknife:6.0.0'
compile 'com.google.code.gson:gson:2.5'
compile 'com.github.bumptech.glide:glide:3.5.2'
compile 'de.greenrobot:eventbus:2.4.0'
compile 'com.squareup.dagger:dagger:1.2.2'
compile 'com.romainpiel.shimmer:library:1.3.0#aar'
compile 'com.michaelpardo:activeandroid:3.1.0-SNAPSHOT'
compile 'info.hoang8f:fbutton:1.0.5'
compile 'com.wrapp.floatlabelededittext:library:0.0.6'
compile 'com.jpardogo.materialtabstrip:library:1.0.9'
compile 'com.github.markushi:circlebutton:1.1'
compile 'com.google.android.gms:play-services-location:8.4.0'
compile 'com.google.android.gms:play-services-maps:8.4.0'
compile 'com.google.android.gms:play-services-plus:8.4.0'
compile 'com.google.android.gms:play-services-identity:8.4.0'
compile 'com.sothree.slidinguppanel:library:3.2.0'
compile 'com.daimajia.swipelayout:library:1.1.9#aar'
compile 'com.nineoldandroids:library:2.4.0'
compile 'com.daimajia.easing:library:1.0.0#aar'
compile 'com.daimajia.androidanimations:library:1.1.2#aar'
compile 'com.roomorama:caldroid:1.1.8'
compile 'joda-time:joda-time:2.3'
compile 'com.github.bmelnychuk:atv:1.2.7'
// compile 'org.apache.commons:commons-lang3:3.0'
// compile('com.github.afollestad.material-dialogs:core:0.8.5.+#aar') {
// transitive = true
// }
// compile('com.github.afollestad.material-dialogs:commons:0.8.5.+#aar') {
// transitive = true
// }
compile 'com.github.PhilJay:MPAndroidChart:v2.1.0'
compile 'com.android.support:design:23.1.1'
compile 'com.github.machinarius:preferencefragment:0.1.1'
compile 'com.readystatesoftware.systembartint:systembartint:1.0.3'
compile 'de.hdodenhof:circleimageview:2.0.0'
compile 'com.amazonaws:aws-android-sdk-core:2.+'
compile 'com.amazonaws:aws-android-sdk-s3:2.+'
compile project(':commons')
compile project(':core')
}
My MainMenu which extends to AppCompatActivity
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// omitted some butterknife injections
if(mToolbar != null ){
setSupportActionBar(mToolbar);
}
mDrawerToggler = new ActionBarDrawerToggle(this ,mDrawer , mToolbar , R.string.drawer_open , R.string.drawer_close ){
#Override
public void onDrawerOpened(View drawerView) {
super.onDrawerOpened(drawerView);
invalidateOptionsMenu();
}
#Override
public void onDrawerClosed(View drawerView) {
super.onDrawerClosed(drawerView);
invalidateOptionsMenu();
}
};
mDrawer.setDrawerListener(mDrawerToggler);
}
#Override
protected void onRestoreInstanceState(#NonNull Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
final int currentIndex = savedInstanceState.getInt(Constants.CURRENT_POSITION);
selectItem(currentIndex);
}
#Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putInt(Constants.CURRENT_POSITION, mListView.getSelectedItemPosition());
}
#Override
public boolean onPrepareOptionsMenu(Menu menu) {
boolean drawerOpen = mDrawer.isDrawerOpen(mLeftDrawer);
hideMenuItems(menu, !drawerOpen);
Log.w(TAG , "onPrepareOptionsMenu(Menu menu)" );
return super.onPrepareOptionsMenu(menu);
}
private void hideMenuItems(Menu menu, boolean visible){
for(int i = 0; i < menu.size(); i++){
menu.getItem(i).setVisible(visible);
}
}
private void selectItem(int position){
final ActionBar actionBar = getSupportActionBar();
Fragment frag = null;
// omitted some fragment selection process
if(frag != null){
getSupportFragmentManager().beginTransaction()
.replace(R.id.content_frame, frag)
//.setTransition(FragmentTransaction.TRANSIT_ENTER_MASK)
// commitAllowingStateLoss() instead of commit()
// this is a known bug on API > 11
// http://stackoverflow.com/a/10261449/3974048
.commitAllowingStateLoss();
}
if( position != Constants.A_LOGOUT || position != Constants.S_LOGOUT ) {
mListView.setItemChecked(position, true);
}
mDrawer.closeDrawer(mLeftDrawer);
mCurrentPosition = position;
}
issue in google :
https://code.google.com/p/android/issues/detail?can=1&start=0&num=100&q=onPrepareOptionsMenu&colspec=ID%20Status%20Priority%20Owner%20Summary%20Stars%20Reporter%20Opened&groupby=&sort=&id=172133
My post:
https://code.google.com/p/android/issues/detail?can=5&start=0&num=100&q=&colspec=ID%20Status%20Priority%20Owner%20Summary%20Stars%20Reporter%20Opened&groupby=&sort=&id=199405#makechanges
Im currently using gradle 2.0.0.alhpa6. latest android studio from canary.

Categories

Resources