NullPointerException by using ExpandableListView - Java for Android App Development

I'm currently trying to combine SlidingMenu (https://github.com/jfeinstein10/SlidingMenu) with ExpandableListView, but i'm running into some issues.
I've got SlidingMenu working fine, and it can inflate a view.
My problem comes when i try to call the .java file associated with the ExpandableListView.
I get a NullPointerException when i try to call methods on my ExpandableListView object, but i've followed guides and google'd around to fix the issue, yet i haven't found a proper way to call the constructor for it.
The constructor requires a Context, but none of the ways i know how to get the context works (it still gives me an error).
I've shown part of my MainActivity below, where i set the SlidingMenu to the correct view (this works fine), and where i start the SlideMainMenu activity (this populates and setups my ExpandableListView).
Code:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
SlidingMenu menu = new SlidingMenu(this);
menu.setMode(SlidingMenu.LEFT);
menu.setFadeEnabled(true);
menu.setShadowDrawable(R.drawable.shadow);
menu.setFadeDegree(0.80f);
menu.setBehindOffset(50);
menu.attachToActivity(this, SlidingMenu.SLIDING_CONTENT);
menu.setMenu(R.layout.expand_listview_main);
//TEST START
Intent intent = new Intent(this, SlideMainMenu.class);
startActivity(intent);
//TEST END
I've also shown part of my SlideMainMenu.java file, more precisely the part that throws the NullPointerException.
The NPE happens when i try to call "expandableListView.setAdapter(listAdapter);"
Code:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.slide_left_main_menu);
expandableListView = (ExpandableListView) findViewById(R.id.ExpandableListView_Main);
prepareListData();
listAdapter = new ExpandableListAdapter(this, listDataHeader, listDataChild);
//TEST START
if(findViewById(R.id.ExpandableListView_Main) == null)
{
Log.d("DAMN","It's a god damn null value - " + expandableListView);
}
else
{
Log.d("DAMN","It's NOT NULL! YAAY! - " + expandableListView);
}
//TEST END
expandableListView.setAdapter(listAdapter);
I've also included the LogCat when the app crashes on a virtual machine.
Code:
02-08 19:06:00.862: V/CustomViewBehind(774): behind INVISIBLE
02-08 19:06:00.911: D/DAMN(774): It's a god damn null value - null
02-08 19:06:00.921: D/AndroidRuntime(774): Shutting down VM
02-08 19:06:00.921: W/dalvikvm(774): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
02-08 19:06:00.921: E/AndroidRuntime(774): FATAL EXCEPTION: main
02-08 19:06:00.921: E/AndroidRuntime(774): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.moon.ihaquiz/com.moon.ihaquiz.SlideMainMenu}: java.lang.NullPointerException
02-08 19:06:00.921: E/AndroidRuntime(774): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
02-08 19:06:00.921: E/AndroidRuntime(774): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
02-08 19:06:00.921: E/AndroidRuntime(774): at android.app.ActivityThread.access$600(ActivityThread.java:141)
02-08 19:06:00.921: E/AndroidRuntime(774): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
02-08 19:06:00.921: E/AndroidRuntime(774): at android.os.Handler.dispatchMessage(Handler.java:99)
02-08 19:06:00.921: E/AndroidRuntime(774): at android.os.Looper.loop(Looper.java:137)
02-08 19:06:00.921: E/AndroidRuntime(774): at android.app.ActivityThread.main(ActivityThread.java:5041)
02-08 19:06:00.921: E/AndroidRuntime(774): at java.lang.reflect.Method.invokeNative(Native Method)
02-08 19:06:00.921: E/AndroidRuntime(774): at java.lang.reflect.Method.invoke(Method.java:511)
02-08 19:06:00.921: E/AndroidRuntime(774): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
02-08 19:06:00.921: E/AndroidRuntime(774): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
02-08 19:06:00.921: E/AndroidRuntime(774): at dalvik.system.NativeStart.main(Native Method)
02-08 19:06:00.921: E/AndroidRuntime(774): Caused by: java.lang.NullPointerException
02-08 19:06:00.921: E/AndroidRuntime(774): at com.moon.ihaquiz.SlideMainMenu.onCreate(SlideMainMenu.java:43)
02-08 19:06:00.921: E/AndroidRuntime(774): at android.app.Activity.performCreate(Activity.java:5104)
02-08 19:06:00.921: E/AndroidRuntime(774): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
02-08 19:06:00.921: E/AndroidRuntime(774): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
02-08 19:06:00.921: E/AndroidRuntime(774): ... 11 more
02-08 19:06:40.946: I/Process(774): Sending signal. PID: 774 SIG: 9
Hope some one can help me out with this problem, and if anyone has ideas to improve my code, feel free to say it as i'm still a bit new to Android/Java and i'm learning as i go.

Moonbloom said:
I'm currently trying to combine SlidingMenu (https://github.com/jfeinstein10/SlidingMenu) with ExpandableListView, but i'm running into some issues.
I've got SlidingMenu working fine, and it can inflate a view.
My problem comes when i try to call the .java file associated with the ExpandableListView.
I get a NullPointerException when i try to call methods on my ExpandableListView object, but i've followed guides and google'd around to fix the issue, yet i haven't found a proper way to call the constructor for it.
The constructor requires a Context, but none of the ways i know how to get the context works (it still gives me an error).
I've shown part of my MainActivity below, where i set the SlidingMenu to the correct view (this works fine), and where i start the SlideMainMenu activity (this populates and setups my ExpandableListView).
Code:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
SlidingMenu menu = new SlidingMenu(this);
menu.setMode(SlidingMenu.LEFT);
menu.setFadeEnabled(true);
menu.setShadowDrawable(R.drawable.shadow);
menu.setFadeDegree(0.80f);
menu.setBehindOffset(50);
menu.attachToActivity(this, SlidingMenu.SLIDING_CONTENT);
menu.setMenu(R.layout.expand_listview_main);
//TEST START
Intent intent = new Intent(this, SlideMainMenu.class);
startActivity(intent);
//TEST END
I've also shown part of my SlideMainMenu.java file, more precisely the part that throws the NullPointerException.
The NPE happens when i try to call "expandableListView.setAdapter(listAdapter);"
Code:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.slide_left_main_menu);
expandableListView = (ExpandableListView) findViewById(R.id.ExpandableListView_Main);
prepareListData();
listAdapter = new ExpandableListAdapter(this, listDataHeader, listDataChild);
//TEST START
if(findViewById(R.id.ExpandableListView_Main) == null)
{
Log.d("DAMN","It's a god damn null value - " + expandableListView);
}
else
{
Log.d("DAMN","It's NOT NULL! YAAY! - " + expandableListView);
}
//TEST END
expandableListView.setAdapter(listAdapter);
I've also included the LogCat when the app crashes on a virtual machine.
Code:
02-08 19:06:00.862: V/CustomViewBehind(774): behind INVISIBLE
02-08 19:06:00.911: D/DAMN(774): It's a god damn null value - null
02-08 19:06:00.921: D/AndroidRuntime(774): Shutting down VM
02-08 19:06:00.921: W/dalvikvm(774): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
02-08 19:06:00.921: E/AndroidRuntime(774): FATAL EXCEPTION: main
02-08 19:06:00.921: E/AndroidRuntime(774): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.moon.ihaquiz/com.moon.ihaquiz.SlideMainMenu}: java.lang.NullPointerException
02-08 19:06:00.921: E/AndroidRuntime(774): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
02-08 19:06:00.921: E/AndroidRuntime(774): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
02-08 19:06:00.921: E/AndroidRuntime(774): at android.app.ActivityThread.access$600(ActivityThread.java:141)
02-08 19:06:00.921: E/AndroidRuntime(774): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
02-08 19:06:00.921: E/AndroidRuntime(774): at android.os.Handler.dispatchMessage(Handler.java:99)
02-08 19:06:00.921: E/AndroidRuntime(774): at android.os.Looper.loop(Looper.java:137)
02-08 19:06:00.921: E/AndroidRuntime(774): at android.app.ActivityThread.main(ActivityThread.java:5041)
02-08 19:06:00.921: E/AndroidRuntime(774): at java.lang.reflect.Method.invokeNative(Native Method)
02-08 19:06:00.921: E/AndroidRuntime(774): at java.lang.reflect.Method.invoke(Method.java:511)
02-08 19:06:00.921: E/AndroidRuntime(774): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
02-08 19:06:00.921: E/AndroidRuntime(774): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
02-08 19:06:00.921: E/AndroidRuntime(774): at dalvik.system.NativeStart.main(Native Method)
02-08 19:06:00.921: E/AndroidRuntime(774): Caused by: java.lang.NullPointerException
02-08 19:06:00.921: E/AndroidRuntime(774): at com.moon.ihaquiz.SlideMainMenu.onCreate(SlideMainMenu.java:43)
02-08 19:06:00.921: E/AndroidRuntime(774): at android.app.Activity.performCreate(Activity.java:5104)
02-08 19:06:00.921: E/AndroidRuntime(774): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
02-08 19:06:00.921: E/AndroidRuntime(774): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
02-08 19:06:00.921: E/AndroidRuntime(774): ... 11 more
02-08 19:06:40.946: I/Process(774): Sending signal. PID: 774 SIG: 9
Hope some one can help me out with this problem, and if anyone has ideas to improve my code, feel free to say it as i'm still a bit new to Android/Java and i'm learning as i go.
Click to expand...
Click to collapse
@Moonbloom
I am amazed that your code compiled
epandableListView = (ExpandableListView) findViewById(R.id.ExpandableListView_Main);
identifire names cannot contain uppercase letters
make sure you have a valid id name and you must assign the same id to the ExpandedListView in the xml layout file
Sent from my GT-S5302 using Tapatalk 2

sak-venom1997 said:
@Moonbloom
I am amazed that your code compiled
epandableListView = (ExpandableListView) findViewById(R.id.ExpandableListView_Main);
identifire names cannot contain uppercase letters
make sure you have a valid id name and you must assign the same id to the ExpandedListView in the xml layout file
Sent from my GT-S5302 using Tapatalk 2
Click to expand...
Click to collapse
Thanks for the help
I changed the android:id from uppercase to lowercase and now it works fine, didn't think that would have any difference..
Now i've got the ExpandableListView loaded and it's showing on my screen, but now i'm facing a new issue.
The ExpandableListView is starting as a new view on top of my MainActivity view, while i wanted it to become a SlidingMenu (accessable from MainActivity).
Once i start the app, the ExpandableListView shows and fills the entire screen, then i can click back and see my MainActivity screen. Though my SlidingMenu is still completely blank.
So how can i make sure the ELV is starting in the SlidingMenu and not as a new activity screen?

Are you setting the listview in the main activity's xml or in the xml for the sliding menu?
Also, I was working with the sliding menu a few months ago and actually found using the official navigation drawer built into the sdk to be much easier. I'd be happy to coordinate efforts with you on getting Expandable listview working in a nav drawer for nothing more than the experience and a possible brief mention when you launch the app. If you're interested, pm me
Sent from my Nexus 4 using Tapatalk

Moonbloom said:
Thanks for the help
I changed the android:id from uppercase to lowercase and now it works fine, didn't think that would have any difference..
Now i've got the ExpandableListView loaded and it's showing on my screen, but now i'm facing a new issue.
The ExpandableListView is starting as a new view on top of my MainActivity view, while i wanted it to become a SlidingMenu (accessable from MainActivity).
Once i start the app, the ExpandableListView shows and fills the entire screen, then i can click back and see my MainActivity screen. Though my SlidingMenu is still completely blank.
So how can i make sure the ELV is starting in the SlidingMenu and not as a new activity screen?
Click to expand...
Click to collapse
Would you mind uploading code of relevent layout files that might just solve it.
And as Wizard Knight said android Sliding menus should genrally be implemented via fragments see http://developer.android.com/design/patterns/navigation-drawer.html
but anyways as you said you're a beginer stick to your approach !
Sent from my GT-S5302 using Tapatalk 2

Wizard Knight said:
Are you setting the listview in the main activity's xml or in the xml for the sliding menu?
Also, I was working with the sliding menu a few months ago and actually found using the official navigation drawer built into the sdk to be much easier. I'd be happy to coordinate efforts with you on getting Expandable listview working in a nav drawer for nothing more than the experience and a possible brief mention when you launch the app. If you're interested, pm me
Sent from my Nexus 4 using Tapatalk
Click to expand...
Click to collapse
I'm setting the listview in the SlidingMenu's XML file, not the main activity's XML file.
I haven't really dived into fragments yet, i just found one way to build the UI up and stuck to it, but when i get a solid foundation i'll most likely switch to fragments
sak-venom1997 said:
Would you mind uploading code of relevent layout files that might just solve it.
And as Wizard Knight said android Sliding menus should genrally be implemented via fragments see http://developer.android.com/design/patterns/navigation-drawer.html
but anyways as you said you're a beginer stick to your approach !
Sent from my GT-S5302 using Tapatalk 2
Click to expand...
Click to collapse
I've uploaded my entire project on my github:
https://github.com/Moonbloom/IHAQuiz
I'm working on implementing settings and some other stuff, so the code might be a bit messy, my apologies.
Thanks for the help

Moonbloom said:
I'm setting the listview in the SlidingMenu's XML file, not the main activity's XML file.
I haven't really dived into fragments yet, i just found one way to build the UI up and stuck to it, but when i get a solid foundation i'll most likely switch to fragments
I've uploaded my entire project on my github:
https://github.com/Moonbloom/IHAQuiz
I'm working on implementing settings and some other stuff, so the code might be a bit messy, my apologies.
Thanks for the help
Click to expand...
Click to collapse
I'm out for the day. Will check it out this evening when I get home
Sent from my Nexus 4 using Tapatalk

@Moonbloom
Just remove the lines where you start an activity enclosed in comments //TEST STAR
//TEST END
Code:
****************//TEST START - If these two lines are enabled, the ExpandableListView will show up as a new activity on top of my MainActivity********Intent intent = new Intent(this, SlideMainMenu.class);startActivity(intent); ********//TEST END
in the MainActivity onCreate method after you declared the menu and it shall work
Sent from my GT-S5302 using Tapatalk 2

sak-venom1997 said:
@Moonbloom
Just remove the lines where you start an activity enclosed in comments //TEST STAR
//TEST END
Code:
****************//TEST START - If these two lines are enabled, the ExpandableListView will show up as a new activity on top of my MainActivity********Intent intent = new Intent(this, SlideMainMenu.class);startActivity(intent); ********//TEST END
in the MainActivity onCreate method after you declared the menu and it shall work
Sent from my GT-S5302 using Tapatalk 2
Click to expand...
Click to collapse
I originally had that, but then the .java file never gets executed and my SlidingMenu doesn't get populated with any data.
Then it simply inflates the 'expand_listview_main' which is just a LinearLayout with an ExpandableListView inside it :/
I added the Intent to make sure the .java file was executed, but then the other problem i mentioned was revealed..

Moonbloom said:
I originally had that, but then the .java file never gets executed and my SlidingMenu doesn't get populated with any data.
Then it simply inflates the 'expand_listview_main' which is just a LinearLayout with an ExpandableListView inside it :/
I added the Intent to make sure the .java file was executed, but then the other problem i mentioned was revealed..
Click to expand...
Click to collapse
So you have now removed these lines ? Because if they are present that activity will be started for sure ...
Could you please post a screenshot of how it looks if you can (sorry not at home cant compile your code )
Sent from my GT-S5302 using Tapatalk 2

sak-venom1997 said:
So you have now removed these lines ? Because if they are present that activity will be started for sure ...
Could you please post a screenshot of how it looks if you can (sorry not at home cant compile your code )
Sent from my GT-S5302 using Tapatalk 2
Click to expand...
Click to collapse
I've commented the lines the make the intent and start the activity, and this is my app:
http://i62.tinypic.com/24e2qyx.png
To the right side of the window you can see some black and the outline of some buttons, those are from my MainActivity.
I've tested if it's actually inflating the correct view by adding a simple Button to the view that it's inflating, and it shows up correctly.

@Moonbloom
Try calling the setBehindWidth funtion of sliding menu
Like menu.setBehindWidth(200);
It might work
NOTE ACTUAL NAME COULD DIFFER A BIT PLEASE CHECK
Sent from my GT-S5302 using Tapatalk 2

sak-venom1997 said:
@Moonbloom
Try calling the setBehindWidth funtion of sliding menu
Like menu.setBehindWidth(200);
It might work
NOTE ACTUAL NAME COULD DIFFER A BIT PLEASE CHECK
Sent from my GT-S5302 using Tapatalk 2
Click to expand...
Click to collapse
That simply changes how much of the SlidingMenu can be seen when it's present, just tested it.
Optimally the SlidingMenu should have a function to call a .java file instead of setMenu() which inflates a XML file, but can't seem to find such a function.
Or, if i could just start the .java file in the background when the app is launched.. That way it would run the .java file and it would inflate the view for the SlidingMenu and set the correct data..
I've tried googl'ing around to start an activity in the background, but all the possible ways i've found seems quite hard for a rather simple (at least i think it is) task.. And i haven't gotten any of them to work either.

@Moonbloom
Insted of starting an activity for background task try AsyncTask
I ll figure this out when i see the source on my computer tomorrow morning its 2 AM here
The amount of view that is shown isnt this what you wanted ? To reduce size so it doesnot hinder your activities visibility ?
Or is that your data is not shown in the listview ??
Sent from my GT-S5302 using Tapatalk 2

sak-venom1997 said:
@Moonbloom
Insted of starting an activity for background task try AsyncTask
I ll figure this out when i see the source on my computer tomorrow morning its 2 AM here
The amount of view that is shown isnt this what you wanted ? To reduce size so it doesnot hinder your activities visibility ?
Or is that your data is not shown in the listview ??
Sent from my GT-S5302 using Tapatalk 2
Click to expand...
Click to collapse
I can adjust the view width without any problems
My real problem is as you said, that none of my data is shown in the listview. The data only gets set when the .java file is executed..
I'll try to check AsyncTask and see
Thanks for all your help

Moonbloom said:
I can adjust the view width without any problems
My real problem is as you said, that none of my data is shown in the listview. The data only gets set when the .java file is executed..
I'll try to check AsyncTask and see
Thanks for all your help
Click to expand...
Click to collapse
oh i got this wrong i ll
Ill see the data one as soon as i can
And the .java files as you say are known as classes a bit more elegant
Sent from my GT-S5302 using Tapatalk 2
---------- Post added at 02:13 AM ---------- Previous post was at 02:02 AM ----------
@Moonbloom
As far i have i ve seen your code you did not call setAdapter(your adapter) on your ExpandableListView
If not then please do so
Sent from my GT-S5302 using Tapatalk 2

sak-venom1997 said:
oh i got this wrong i ll
Ill see the data one as soon as i can
And the .java files as you say are known as classes a bit more elegant
Sent from my GT-S5302 using Tapatalk 2
---------- Post added at 02:13 AM ---------- Previous post was at 02:02 AM ----------
@Moonbloom
As far i have i ve seen your code you did not call setAdapter(your adapter) on your ExpandableListView
If not then please do so
Sent from my GT-S5302 using Tapatalk 2
Click to expand...
Click to collapse
I do call setAdapter() in my SlidingMainMenu.java class onCreate()
Code:
expandableListView.setAdapter(listAdapter);
I'm starting to think i should just change to Navigation Drawer as it's more known (as it's in the official SDK instead of an imported library), so it should be easier to get working and find guides/help on google about it.. :/

@Moonbloom
Using android APIs is always the best option but here your issue isnt whith the sliding menu its with your ListAdapter
But you're not in the SlidingMainMenu.java
instead you are in MainActivity i guess
Try calling it there
Sent from my GT-S5302 using Tapatalk 2

sak-venom1997 said:
@Moonbloom
Using android APIs is always the best option but here your issue isnt whith the sliding menu its with your ListAdapter
But you're not in the SlidingMainMenu.java
instead you are in MainActivity i guess
Try calling it there
Sent from my GT-S5302 using Tapatalk 2
Click to expand...
Click to collapse
Try calling what there?
The setAdapter()?
I can't move the function into the MainActivity as my ExpandableListView object and ExpandableListAdapter object are created in the SlideMainMenu and therefore not known in MainActivity..

Moonbloom said:
Try calling what there?
The setAdapter()?
I can't move the function into the MainActivity as my ExpandableListView object and ExpandableListAdapter object are created in the SlideMainMenu and therefore not known in MainActivity..
Click to expand...
Click to collapse
The SlidingMenu inflates your ExpandedListView layout there in the MainActivity and that is what you see
Get your EListView after SlidingMenu menu..........
and there create a new instance if your adapter and assign it to list view
Sent from my GT-S5302 using Tapatalk 2

Related

[PROJECT] JIT enabled Dalvik VM

Just saw this and I was wondering how much work it would take to get this working.
http://forum.xda-developers.com/showthread.php?t=637419
Based on what I've seen on blogs and in various other cooked rom projects, it's a lot of work for something that is very unstable.
I already have a working patch for 0.3 but it does cause some instability.
We've already got JIT's running. They're not in any of the public roms/updates yet though. I've been running them, and so has jcase I think. Myself, I haven't had any issues really.
They definitely make the phone a little snappier, and I haven't had any stability issues so far.
Here's some benchmarks I ran with Linpack:
No JIT's MFLOPS: 2.239
JIT's MFLOPS: 3.453
(average of 3 tests each)
ivanmmj said:
I already have a working patch for 0.3 but it does cause some instability.
Click to expand...
Click to collapse
Can I get a copy of the patch just to play with?
binny1007 said:
Can I get a copy of the patch just to play with?
Click to expand...
Click to collapse
PM sent
..
Binny,
Come hit me on irc. I have been wrong it for a while now, with what ivan gave me.
-jcase
from my workings with jit in various roms. is that in some roms it works well and others it doesnt. ive found that aosp builds tend to have the best luck with jit as in not having high issue rates. ive added and removed it from builds that ive made for the heroc for my own reasons. one being as i or the beta testers i used wouldnt have any issues. but as soon as i released it and the rest of the community would use the build, issues would then begin to arise from having JIT enabled. because not everyone sets up their phone the same nor uses it in the same manner. so i ended up making it a users choice to setup jit or not and just leaving it out of my hands to deal with. as when i release a build i shoot for stable and fast for all users. with as little bugs and issues as possible. ive found other methods to increase speed and stability that have show good results for all users of my builds. plus i found most users want a fast and stable base build that they can just add to or mod to their liking.
again this is all based on the users on the Heroc forums. i assume the Eris will be in the same boat, as its basically the same device.
I have been running jit fine for a while now, however I reboot my phone atleast twice a day messing with stuff.
jcase said:
I have been running jit fine for a while now, however I reboot my phone atleast twice a day messing with stuff.
Click to expand...
Click to collapse
only twice
jcase said:
I have been running jit fine for a while now, however I reboot my phone atleast twice a day messing with stuff.
Click to expand...
Click to collapse
Alteast twice
trying to get this running on my rom experimentally and it loads fine then dalvik crashes the system
this is what logcat gives me
Code:
D/VoiceDialerReceiver( 661): onReceive Intent { act=android.intent.action.BOOT_COMPLETED cmp=com.android.voicedialer/.VoiceDialerReceiver }
I/HtcLockScreen( 472): touch ACTION_DOWN
D/LockExchangeUtils( 472): isLockExchangeEnabled = false
D/LockExchangeUtils( 472): isLockExchangeEnabled = false
I/HtcLockScreen( 472): touch ACTION_UP
W/dalvikvm( 472): No implementation found for native Ldalvik/system/VMRuntime;.disableGcForExternalAlloc (Z)V
W/dalvikvm( 472): threadid=41: thread exiting with uncaught exception (group=0x4001e2e0)
E/AndroidRuntime( 472): Uncaught handler: thread WindowManagerPolicy exiting due to uncaught exception
E/AndroidRuntime( 472): *** EXCEPTION IN SYSTEM PROCESS. System will crash.
E/AndroidRuntime( 472): java.lang.UnsatisfiedLinkError: disableGcForExternalAlloc
E/AndroidRuntime( 472): at dalvik.system.VMRuntime.disableGcForExternalAlloc(Native Method)
E/AndroidRuntime( 472): at com.htc.lockscreen.HtcLockScreen.onInterceptTouchEvent(HtcLockScreen.java:2643)
E/AndroidRuntime( 472): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:897)
E/AndroidRuntime( 472): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:924)
E/AndroidRuntime( 472): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:924)
E/AndroidRuntime( 472): at android.view.ViewRoot.handleMessage(ViewRoot.java:1697)
E/AndroidRuntime( 472): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime( 472): at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime( 472): at com.android.server.WindowManagerService$PolicyThread.run(WindowManagerService.java:611)
I/Process ( 472): Sending signal. PID: 472 SIG: 9
D/dalvikvm( 594): GC freed 2926 objects / 229136 bytes in 167ms
D/CalendarProvider( 644): deleteRowsForRemovedAccounts need to check count: 0
D/CalendarProvider( 644): deleteRowsForRemovedAccounts need to check count: 0
V/CalendarProvider( 644): onAccountsChanged
D/CalendarProvider( 644): deleteRowsForRemovedAccounts need to check count: 2
V/CalendarProvider( 644): accounts didn't contains: Account {[email protected], type=com.google} -- SKIP [no need to delete]
E/ActivityThread( 531): Failed to find provider info for call_log
I/ServiceManager( 52): service 'activity' died
I/ServiceManager( 52): service 'meminfo' died
I/ServiceManager( 52): service 'batteryinfo' died
I/ServiceManager( 52): service 'telephony.registry' died
I/ServiceManager( 52): service 'entropy' died
I/ServiceManager( 52): service 'power' died
i would really like to get it working any help is appreciated
i ran into constant crashing trying to get this working? It seems as though sense does not play nice with jit enabled.
binny1007 said:
i ran into constant crashing trying to get this working? It seems as though sense does not play nice with jit enabled.
Click to expand...
Click to collapse
yeah, its the main sense elements that don't play nice with jit. i've tried messing with it a few times before, but eventually its pretty much the non-sense roms(or AOSP) that work with jit. unless there's some sort of tweak we can do to sense(both the lockscreen and sense itself), jit probably won't work with non-aosp roms.
I got it to work! =)
jamezelle said:
trying to get this running on my rom experimentally and it loads fine then dalvik crashes the system
this is what logcat gives me
Code:
D/VoiceDialerReceiver( 661): onReceive Intent { act=android.intent.action.BOOT_COMPLETED cmp=com.android.voicedialer/.VoiceDialerReceiver }
I/HtcLockScreen( 472): touch ACTION_DOWN
D/LockExchangeUtils( 472): isLockExchangeEnabled = false
D/LockExchangeUtils( 472): isLockExchangeEnabled = false
I/HtcLockScreen( 472): touch ACTION_UP
W/dalvikvm( 472): No implementation found for native Ldalvik/system/VMRuntime;.disableGcForExternalAlloc (Z)V
W/dalvikvm( 472): threadid=41: thread exiting with uncaught exception (group=0x4001e2e0)
E/AndroidRuntime( 472): Uncaught handler: thread WindowManagerPolicy exiting due to uncaught exception
E/AndroidRuntime( 472): *** EXCEPTION IN SYSTEM PROCESS. System will crash.
E/AndroidRuntime( 472): java.lang.UnsatisfiedLinkError: disableGcForExternalAlloc
E/AndroidRuntime( 472): at dalvik.system.VMRuntime.disableGcForExternalAlloc(Native Method)
E/AndroidRuntime( 472): at com.htc.lockscreen.HtcLockScreen.onInterceptTouchEvent(HtcLockScreen.java:2643)
E/AndroidRuntime( 472): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:897)
E/AndroidRuntime( 472): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:924)
E/AndroidRuntime( 472): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:924)
E/AndroidRuntime( 472): at android.view.ViewRoot.handleMessage(ViewRoot.java:1697)
E/AndroidRuntime( 472): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime( 472): at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime( 472): at com.android.server.WindowManagerService$PolicyThread.run(WindowManagerService.java:611)
I/Process ( 472): Sending signal. PID: 472 SIG: 9
D/dalvikvm( 594): GC freed 2926 objects / 229136 bytes in 167ms
D/CalendarProvider( 644): deleteRowsForRemovedAccounts need to check count: 0
D/CalendarProvider( 644): deleteRowsForRemovedAccounts need to check count: 0
V/CalendarProvider( 644): onAccountsChanged
D/CalendarProvider( 644): deleteRowsForRemovedAccounts need to check count: 2
V/CalendarProvider( 644): accounts didn't contains: Account {[email protected], type=com.google} -- SKIP [no need to delete]
E/ActivityThread( 531): Failed to find provider info for call_log
I/ServiceManager( 52): service 'activity' died
I/ServiceManager( 52): service 'meminfo' died
I/ServiceManager( 52): service 'batteryinfo' died
I/ServiceManager( 52): service 'telephony.registry' died
I/ServiceManager( 52): service 'entropy' died
I/ServiceManager( 52): service 'power' died
i would really like to get it working any help is appreciated
Click to expand...
Click to collapse
I have been spending some hours reversing the libdvm.so and how dalvik works and i have been successfull on enabling it.
What I did was to get the latest android sources, enable jit in buildspec.mk.
After this, i get the same error as you got.
So i modified the dalvik/vm/native/dalvik_system_VMRuntime.c, here is a diff:
Code:
--- a/vm/native/dalvik_system_VMRuntime.c
+++ b/vm/native/dalvik_system_VMRuntime.c
@@ -178,6 +178,13 @@ static void
Dalvik_dalvik_system_VMRuntime_getExternalBytesAllocated(
RETURN_LONG((s8)dvmGetExternalBytesAllocated());
}
+static void Dalvik_dalvik_system_VMRuntime_disableGcForExternalAlloc(
+ const u4* args, JValue* pResult)
+{
+ RETURN_VOID();
+}
+
+
const DalvikNativeMethod dvm_dalvik_system_VMRuntime[] = {
{ "getTargetHeapUtilization", "()F",
Dalvik_dalvik_system_VMRuntime_getTargetHeapUtilization },
@@ -195,6 +202,10 @@ const DalvikNativeMethod dvm_dalvik_system_VMRuntime[] = {
Dalvik_dalvik_system_VMRuntime_trackExternalFree },
{ "getExternalBytesAllocated", "()J",
Dalvik_dalvik_system_VMRuntime_getExternalBytesAllocated },
+ { "disableGcForExternalAlloc", "(Z)V",
+ Dalvik_dalvik_system_VMRuntime_disableGcForExternalAlloc },
{ NULL, NULL, NULL },
};
I have also attached the compiled libdvm.so if anyone wants to try.
Note: Sense is crashing some times,with OutOfMemory exception, probably due to my dummy implementation of the function.
Would be cool to get this "stable" =)
nilo85 said:
I have been spending some hours reversing the libdvm.so and how dalvik works and i have been successfull on enabling it.
What I did was to get the latest android sources, enable jit in buildspec.mk.
After this, i get the same error as you got.
So i modified the dalvik/vm/native/dalvik_system_VMRuntime.c, here is a diff:
Code:
--- a/vm/native/dalvik_system_VMRuntime.c
+++ b/vm/native/dalvik_system_VMRuntime.c
@@ -178,6 +178,13 @@ static void
Dalvik_dalvik_system_VMRuntime_getExternalBytesAllocated(
RETURN_LONG((s8)dvmGetExternalBytesAllocated());
}
+static void Dalvik_dalvik_system_VMRuntime_disableGcForExternalAlloc(
+ const u4* args, JValue* pResult)
+{
+ RETURN_VOID();
+}
+
+
const DalvikNativeMethod dvm_dalvik_system_VMRuntime[] = {
{ "getTargetHeapUtilization", "()F",
Dalvik_dalvik_system_VMRuntime_getTargetHeapUtilization },
@@ -195,6 +202,10 @@ const DalvikNativeMethod dvm_dalvik_system_VMRuntime[] = {
Dalvik_dalvik_system_VMRuntime_trackExternalFree },
{ "getExternalBytesAllocated", "()J",
Dalvik_dalvik_system_VMRuntime_getExternalBytesAllocated },
+ { "disableGcForExternalAlloc", "(Z)V",
+ Dalvik_dalvik_system_VMRuntime_disableGcForExternalAlloc },
{ NULL, NULL, NULL },
};
I have also attached the compiled libdvm.so if anyone wants to try.
Note: Sense is crashing some times,with OutOfMemory exception, probably due to my dummy implementation of the function.
Would be cool to get this "stable" =)
Click to expand...
Click to collapse
hmm i tried running your patch but it didnt fully take on the source
Code:
[email protected]:~/mydroid/dalvik$ patch -p1 < /home/jamezelle/desktop/dalvikpatch
patching file vm/native/dalvik_system_VMRuntime.c
Hunk #1 succeeded at 177 with fuzz 2 (offset -1 lines).
missing header for unified diff at line 18 of patch
can't find file to patch at input line 18
Perhaps you used the wrong -p or --strip option?
The text leading up to this was:
--------------------------
| Dalvik_dalvik_system_VMRuntime_getTargetHeapUtilization },
--------------------------
File to patch:
Patch
Hi, it was just a simple "git diff" command, seems to be a little bit different from patch format.
I was recently wiping my phone, and at init starting with this libdvm.so, and i noticed that there was another symbol not beeing exported, was to tired to look it up at that time, but running a already dexopted system, seems pretty "stable", except of Launcher crashing from time to time of OutOfMemory.
Here's a patch for the previous post:
Code:
*** mydroid/dalvik/vm/native/dalvik_system_VMRuntime.c 2010-03-12 12:15:12.000000000 +0100
--- mydroid_edit/dalvik/vm/native/dalvik_system_VMRuntime.c 2010-04-08 19:38:12.000000000 +0200
***************
*** 178,183 ****
--- 178,190 ----
RETURN_LONG((s8)dvmGetExternalBytesAllocated());
}
+ static void Dalvik_dalvik_system_VMRuntime_disableGcForExternalAlloc(
+ const u4* args, JValue* pResult)
+ {
+ RETURN_VOID();
+ }
+
+
const DalvikNativeMethod dvm_dalvik_system_VMRuntime[] = {
{ "getTargetHeapUtilization", "()F",
Dalvik_dalvik_system_VMRuntime_getTargetHeapUtilization },
***************
*** 195,200 ****
--- 202,209 ----
Dalvik_dalvik_system_VMRuntime_trackExternalFree },
{ "getExternalBytesAllocated", "()J",
Dalvik_dalvik_system_VMRuntime_getExternalBytesAllocated },
+ { "disableGcForExternalAlloc", "(Z)V",
+ Dalvik_dalvik_system_VMRuntime_disableGcForExternalAlloc },
{ NULL, NULL, NULL },
};

My newbie thread.

Some background: 10 years ago I had classes in basic, pascal, and c++( I missed something simple some where with functions or classes which messed me up in this I believe.)
So far I've watched a tutorial and set up my emulator and eclipse..
http://www.youtube.com/watch?v=z7bvrikkG7c
I then did a tutorial that ran my first program helloworld
http://www.youtube.com/watch?v=2gdhvwYUNJQ
I then did a tutorial and made a simple program that changes between two screens on a button click ( Why it is an hour long is beyond my understanding)
http://www.youtube.com/watch?v=m-C-QPGR2pM
I've proceeded to learning how to create menus and simply retrieved example code from the Google android site
Source: http://developer.android.com/guide/topics/ui/menus.html
Here's an example of this procedure, inside an Activity, wherein we create an Options Menu and handle item selections:
/* Creates the menu items */
public boolean onCreateOptionsMenu(Menu menu) {
menu.add(0, MENU_NEW_GAME, 0, "New Game");
menu.add(0, MENU_QUIT, 0, "Quit");
return true;
}
/* Handles item selections */
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case MENU_NEW_GAME:
newGame();
return true;
case MENU_QUIT:
quit();
return true;
}
return false;
}
Click to expand...
Click to collapse
As I copy and pasted it into ecplise within an Activity, I realize there is some assumed information that I am missing when i received a bunch of errors
So.. I found A video tutorial
http://www.youtube.com/watch?v=6UYNnQOxCS8
and it instructs me to make sure I put these two lines of codes in first
Private static final int MENU1 = MENU.FIRST;
private static final int MENU2 = MENU.FIRST + 1;
I under line the menu's because it gives me errors on them as well... there seems to be some assumed knowledge I'm missing as well....
What specific piece of information am I missing to not have known that i would need those two lines as well as what I need to do to know the appropriate fix out of the suggestions they give me...
Are there any online tutorials or videos that'll bring me up to speed specifically with programming android apps... all the stuff I find just keeps leading me down a path to where I realize I've gotten ahead of myself because people are teaching things while assuming certain knowledge is known.
The tutorial I am following and getting errors on is for an 8th grade class of students...
Me: I'm pissed at that java toturial...
http://forum.xda-developers.com/showpost.php?p=6521891&postcount=6
Bastards.
Following the suggestion from this post
http://forum.xda-developers.com/showpost.php?p=6522089&postcount=7
I obtained a copy of Hello android.
Following the example to create a menu I used the code
I place this into my strings.xml
<string name="settings_label">Settings...</string>
name="settings_title">Sudoku settings</string>
<string
<string name="settings_shortcut">s</string>
<string name="music_title">Music</string>
<string name="music_summary">Play background music</string>
<string name="hints_title">Hints</string>
<string name="hints_summary">Show hints during play</string>
Click to expand...
Click to collapse
I place this into my main.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/settings"
android:title="@string/settings_label"
android:alphabeticShortcut="@string/settings_shortcut" />
</menu>
Click to expand...
Click to collapse
I import this files into my src app.java
right uner the other imports
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
Click to expand...
Click to collapse
I place this inside my activity ( where I think it would belong since it doesn't say where to put it. ) and ERROR
@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu, menu);
return true;
}
Click to expand...
Click to collapse
Quick fix says that menu needs to be either a field or constast so i give it a go and click field and it modifies a file called R.java.
I go back to app.java and not only is the menu highlighted but now R.menu.menu is entirely highlighted and says cannot be resolved or is not a field..
I try to modify the R.java file to remove what its done...
It won't let me..
Epic fail. on the third tutorial to create a menu.
I guess ill redo everything in a new project and then do the quick fix making menu a constant....
[edit] never mind ill look else where for help
http://www.youtube.com/watch?v=X3QO0ffg2Tc&feature=related
ok the toturial looks like it will work but when he types in this line in his app.java
public boolean onCreateOptionsMenu(Menu menu) {
Click to expand...
Click to collapse
it is under lined with an error on his screen as well as mine and then he says he is importing the missing classes and the error just disappeas with no demonstrations of what missing classing or what key combination he used to import them...
http://www.google.com/#hl=en&q=impo...=f&aqi=&aql=&oq=&gs_rfai=&fp=d059ab474882bfe2
WOO HOO found what he left out...
Compiled and installed...
Boo hoo menu key does nothing!! time to go back through the other menu tutorials and see if i cant get it working now that i know of this hot key..
Went back to this toturial with the elusive import missing classes hotkey..
http://www.youtube.com/watch?v=6UYNnQOxCS8
It worked like a charm
just had to remove
newGame();
and
quit();
and i have buttons that do nothing so far
More missing pieces.
I created a new activity as shown to me in previous tutorials giving it its own seperate XML file in the res/layouts as well as a jave file and I made sure it is calling for the right layout.
I also added the activity in the androidmanifest as shown to me as well..
off this site
http://developer.android.com/guide/topics/ui/menus.html
I've taken the code to create menus.. ( i got it working )
I then followed this and made the changes
Set an intent for a single menu item
If you want to offer a specific menu item that launches a new Activity, then you can specifically define an Intent for the menu item with the setIntent() method.
For example, inside the onCreateOptionsMenu() method, you can define a new menu item with an Intent like this:
MenuItem menuItem = menu.add(0, PHOTO_PICKER_ID, 0, "Select Photo");
menuItem.setIntent(new Intent(this, PhotoPicker.class));
Android will automatically launch the Activity when the item is selected.
Note: This will not return a result to your Activity. If you wish to be returned a result, then do not use setIntent(). Instead, handle the selection as usual in the onOptionsMenuItemSelected() or onContextMenuItemSelected() callback and call startActivityForResult().
Click to expand...
Click to collapse
It doesn't work... I don't understand why the intent would be in the onCreateOptionsMenu... it doesn't seem to work so I tried the alternative and replaced setIntent with with startActivityForResult.. and then I noticed it says "As usual" in the onOptionsMenuItemSelected()... which is where I would think the code would belong in the first place... but when I originally failed and tried to move the code there it errors...
Is ever step of the way really going to be half assed instructions.. i was beginning to think I had the hang of this.
Are the instructions bad or am i missing something???
Guess ill go dig in my hello android book.
EDIT: Wow that helped
startActivity(new Intent(this, register.class));
Click to expand...
Click to collapse
guess that book is worth something after all...
guess im just intending to start an activity with a particular intent and setting an intent alone isn't going to start the activity.... i suppose there must be some purpose behind setting an intent as they had describe on the google page.. just not seeing it yet...
Got to what i wanted tho.

Inflating layout XML files and layout parameters

Why are the layout parm's specified in a layouts XML file not used when you inflate the layout manually in Java. This is a view that is being added to another view.
I have to manually create the layout parms using something like the following after inflating
and before adding to the parent view.
LayoutParams lp = new LayoutParams(-1,-2);
inflatedView.setLayoutParams(lp);
Is there a way to make the newly created view adhere to what is in the XML. I really
hate doing this in Java and divorcing it from the layout's definition.
TIA!
use the LayoutInflater service
Code:
// getSystemService is a method for context and can be called directly from an activity
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
myView = inflater.inflate(R.layout.my_layout, null);
Even better, use the
Code:
inflate(XmlPullParser parser, ViewGroup root, boolean attachToRoot)
variant with the future parent of the inflated view (with attachToRoot set to false if needed, as required for ListViews) to properly inherit LayoutParams from the parent.
And I simply use LayoutInflater.from(Context) instead of getSystemService(), makes it easy to chain the call :
Code:
LayoutInflater.from(context).inflater(R.layout.my_layout, parent, false);
seydhe said:
Even better, use the
Code:
inflate(XmlPullParser parser, ViewGroup root, boolean attachToRoot)
variant with the future parent of the inflated view (with attachToRoot set to false if needed, as required for ListViews) to properly inherit LayoutParams from the parent.
And I simply use LayoutInflater.from(Context) instead of getSystemService(), makes it easy to chain the call :
Code:
LayoutInflater.from(context).inflater(R.layout.my_layout, parent, false);
Click to expand...
Click to collapse
I'm not a fan of chaining calls but that's a style thing. I don't really like the readability/debugability/maintainability of them down the line. But again that's just a subjective opinion, to each their own.
And of course what you posted is pretty readable. But I don't think you really meant to pass an int to the XMLPullParser?
Also why do the API docs say this then...
http://developer.android.com/reference/android/view/LayoutInflater.html
This class is used to instantiate layout XML file into its corresponding View objects. It is never be used directly -- use getLayoutInflater() or getSystemService(String) to retrieve a standard LayoutInflater instance that is already hooked up to the current context and correctly configured for the device you are running on. For example:
Code:
LayoutInflater inflater = (LayoutInflater)context.getSystemService
Context.LAYOUT_INFLATER_SERVICE);
Click to expand...
Click to collapse
Is there some danger to using the static LayoutInflater.from(context) ? Or just a badly worded api that is telling us not to instantiate the LayoutInflater ourselves? (I'm guessing the latter).

[Q] How to keep layouts inflated after activity restarts

Hi guys,
On a button click I am inflating a layout like so:
Code:
public void plusLayout(View v) {
// inflating layout here:
LinearLayout ll1 = (LinearLayout) findViewById(R.id.main_layout);
// this layout is being inflated:
View newView = getLayoutInflater().inflate(R.layout.layout_to_be_added, null);
// add layout
ll1.addView(newView);
}
But when the activity restarts, the inflated layouts are gone.
I'd like the layouts to stay there.
(The user can click a button to remove the layout by hand).
I must be missing something trivial here right?
Cheers,
Daan
Which way is it restarted?
If the complete app is restarted, a new layout will be set in the onCreate method.
nikwen said:
Which way is it restarted?
If the complete app is restarted, a new layout will be set in the onCreate method.
Click to expand...
Click to collapse
Yeah when you press back button and start the app again or completely kill it.
It also happens on orientation change as the activity get restarted then as well.
But I think you can override that in the manifest somewhere.
DaanJordaan said:
Yeah when you press back button and start the app again or completely kill it.
It also happens on orientation change as the activity get restarted then as well.
But I think you can override that in the manifest somewhere.
Click to expand...
Click to collapse
Ah ok.
The point is: If you open the app or turn your device, the onCreate method is called. There you set a completely new layout. You would need to save that the layout is inflated (you could use a SharedPreferences entry) and inflate it in the onCreate method. If you just want it to appear again after turning the device, use the onSaveInstanceState method and the onRestoreInstanceState method. That would be better practice.
Look at the activity lifecycle.
Just so I'm sure I get this right :
The user launches the app, the layouts are not inflated
He presses a button which calls your plusLayout() method, so the layouts are now inflated
The user quits the activity and restarts it, the layouts are not inflated anymore but you want them to.
Is that correct ?
If it is, 2 ways I can think of :
Overriding savedInstanceState() & onRestoreInstanceState() :
First, declare a private Boolean before the onCreate() of your activity :
Code:
private Boolean isInflated = false;
Then, set it to true in the onClick() of your button, and override savedInstanceState and onRestoreInstanceState like so :
Code:
@Override
public void onSaveInstanceState(Bundle savedInstanceState) {
super.onSaveInstanceState(savedInstanceState);
// Save state changes to the savedInstanceState.
// This bundle will be passed to onCreate if th activity is
// killed and restarted.
savedInstanceState.putBoolean("inflate", isInflated);
}
Code:
@Override
public void onRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
// Restore UI state from the savedInstanceState.
// This bundle has also been passed to onCreate.
Boolean myBoolean = savedInstanceState.getBoolean("inflate");
if (myBoolean == true)
plusLayout(myView);
}
Using the sharedPreferences
Same logic, different way to save the boolean :
Before onCreate(), declare a private boolean and a private SharedPreferences :
Code:
private Boolean isInflated = false;
private SharedPreferences prefs = getSharedPreferences("MY_PREFS");
in the onClick of your button :
Code:
isInflated = true;
Editor e = prefs.edit();
e.putBoolean("inflate", isInflated);
e.commit();
Then, in your onCreate(), retrieve the stored value and if it's true, call your plusLayout() method :
Code:
Boolean doInflate = prefs.getBoolean("inflate", false // this is the default value);
if (doInflate == true)
plusLayout(myView);
nikwen said:
Ah ok.
The point is: If you open the app or turn your device, the onCreate method is called. There you set a completely new layout. You would need to save that the layout is inflated (you could use a SharedPreferences entry) and inflate it in the onCreate method. If you just want it to appear again after turning the device, use the onSaveInstanceState method and the onRestoreInstanceState method. That would be better practice.
Look at the activity lifecycle.
Click to expand...
Click to collapse
Okay I'm working on that at the moment.
Whenever a layout is created an (int) "counter" get incremented.
I will save this "counter" in the SharedPreferences.
When the app starts layouts get created "counter" times.
Is this good practice?
It seems so strange that there isn't an easier way to save layout/activity states.
Edit:
Androguide.fr said:
Just so I'm sure I get this right :
The user launches the app, the layouts are not inflated
He presses a button which calls your plusLayout() method, so the layouts are now inflated
The user quits the activity and restarts it, the layouts are not inflated anymore but you want them to.
Is that correct ?
Click to expand...
Click to collapse
That is correct. Big thanks for the examples.
DaanJordaan said:
Okay I'm working on that at the moment.
Whenever a layout is created an (int) "counter" get incremented.
I will save this "counter" in the SharedPreferences.
When the app starts layouts get created "counter" times.
Is this good practice?
It seems so strange that there isn't an easier way to save layout/activity states.
Edit:
That is correct. Big thanks for the examples.
Click to expand...
Click to collapse
I would use his snippets. They are good (as always). Decide which one to use by what I have given above:
Just for turning:
onSaveInstanceState and onRestoreSavedInstanceState
For turning and reopening:
Shared preferences

(Q) fragments with mplayer.

Could someone help me add a m player and a setonclicklistener in a fragment. I have a couple of sound bite apps and I am trying to put them together in a Viewpager. I have the layout all set up, but im not sure on how to have the m player to the fragment. Thanks.
Sent from my SCH-I535 using Tapatalk 2
Set an onClickListener by using the setOnClickListener() method in the onCreateView() method.
If you set the onClick attribute in the xml, it will look for the method in your Activity.
The MediaPlayer requires a Context, right? Pass your Activity which you can get by calling getActivity().
u can use fragmentpagerapteradapter
to assign fragment as viewpager child...

Categories

Resources