I've got an application written with minSdkVersion="8" and targetSdkVersion="19", because is so simple and I need it to be used on low level android devices.
The problem is when I try to use it in an Android 4+ device. I cannot see the Options menu.
When I use the app in the Emulator, I use the "Menu" button, and I can see it. But not in my tablet or mobile phone (both with 4+ version).
Okay, let's see the code:
In the manifest.xml file I have this (I think the problem is the theme...).
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#android:style/Theme.Holo.Light" >
<activity
android:name="com.clv.app2.MainActivity"
android:label="#string/app_name"
android:theme="#android:style/Theme">
And I have a simple OnCreateOptionsMenu like this in MainActivity... (I have defined only two options).
#Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.option_menu, menu);
return true;
}
Can anyone can help me to see where is the problem with this?
Thank you in advance.
EDIT:
option_menu.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/scan"
android:icon="#android:drawable/ic_menu_search"
android:title="#string/connect"/>
<item
android:id="#+id/discoverable"
android:icon="#android:drawable/ic_menu_mylocation"
android:title="#string/discoverable"/>
EDIT:
Okay. I have been reading other entries in forum, and I see that there are devices that have not a menu key (to show options menu), and from 3+ version it is not required to have it.
When I execute my application in an Android device less than 3 version, I have that physical button, and it works. In an Android device more than 3 version (I have one with 4+ version), that button does not exists, and there are no way to make the options menu visible.
My question is... Do I have to put a button in screen on 3+ devices with no "physical menu button", to use it when I want to see the options menu???
I have found the problem that make the application not work on 4+ devices.
In the onCreate method I have in my MainActivity, I have this:
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.d(TAG, "En onCreate...");
// Preparo texto cabecera de pantalla
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.main);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,
R.layout.custom_title);
If I take all that code out, leaving only setContentView it works.
It think the issue is in your activity schema.
First change schema in AndroidManifest to yours:
<activity
android:name="com.clv.app2.MainActivity"
android:label="#string/app_name"
android:theme="#style/MyTheme">
Create styles_mytheme.xml in values folder with lines:
<resources>
<style name="Theme.MyTheme" parent="#android:style/Theme"/>
</resources>
Or just add next line to any styles files:
<style name="Theme.MyTheme" parent="#android:style/Theme"/>
Create folder values-v11 and create file there styles_mytheme.xml:
<resources>
<style name="Theme.MyTheme" parent="#android:style/Theme.Holo"/>
</resources>
So basically your Activity will use default theme for old devices and Holo for devices from v11.
I think its not a problem of theme, but while creating your project just make changes like:
Minimum Required SDK: API8: Android 2.2(Froyo)
Target SDK: API17:Android 4.2(Jelly Bean)
Compile With: API8: Android 2.2(Froyo)
Theme: None
Hope it will work.
Related
I have crash that in my app that I have never managed to reproduce myself but that I know happens occasionally because I can see that in the Google Analytics console.
The crash happens as the user launches the application. An exception is raised when I call setContentView in my Activity derived class
H:0kfgjhA== T:main RuntimeException(Unable to start activity ComponentInfo{com.mydomain·myapp/com.mydomain·myapp.activity.history.HistoryActivit) Cause: NotFoundException(Resource ID #0x7f020134) S:24 00:Resources:android.content.res.Resources.getValue:1274
01:Resources:android.content.res.Resources.getDrawable:797
02:Context:android.content.Context.getDrawable:402
03:ToolbarWidgetWrapper:com.android.internal.widget.ToolbarWidgetWrapper.setIcon:320
04:ActionBarOverlayLayout:com.android.internal.widget.ActionBarOverlayLayout.setIcon:738
05:PhoneWindow:com.android.internal.policy.impl.PhoneWindow.setDefaultIcon:1623
06:Activity:android.app.Activity.initWindowDecorActionBar:2139
07:Activity:android.app.Activity.setContentView:2154
09:MyActivity:com.mydomain·myapp.activity.MyActivity.onCreate:121
The resource that I set in the call to setContentView is an empty FrameLayout
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/content_frame">
</FrameLayout>
The resource that the Resource class cannot find is the application icon (ID #0x7f020134). That icon is only referenced at one place and that is in the manifest file
<application
android:name=".MyApplication"
android:allowBackup="false"
android:icon="#drawable/my_launcher_icon"
.../>
It seems as this defect appeared after we included the appcompat support library v7. That is done in the manifest file (in the dependencies section)
compile 'com.android.support:appcompat-v7:23.1.1'
Does anybody know anything about this problem? How can I fix it?
According to Google Analytics the crash seems to happen only on 5.0, 5.01 and 5.1.1 devices. And it is not a very frequent crash and it is very stochastic.
Thanks
Ola, Sweden
Edit:
The oncreate function looks like this:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (android.os.Build.VERSION.SDK_INT >= 21) {
getWindow().requestFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
}
setContentView(R.layout.activity_trackid);
}
You can add this line in application tag
android:theme="#style/AppTheme"
Like:
<application
android:theme="#style/AppTheme"
android:name=".MyApplication"
android:allowBackup="false"
android:icon="#drawable/my_launcher_icon"
/>
iam following the basic beginner Tutorial on the Android Developer Site. Now, i there is described how to bring the app icon as the Up Button (see last text): http://developer.android.com/training/basics/actionbar/adding-buttons.html#UpNav
I put "getSupportActionBar().setDisplayHomeAsUpEnabled(true);" in my activitys onCreate() Methods, but on my Device my App has no App Icon as the Button. Here are my activities
public class MainActivity extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
and
public class DisplayMessageActivity extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
// Get the message from the intent
Intent intent = this.getIntent();
String message = intent.getStringExtra(MainActivity.EXTRA_MESSAGE);
// Create the text view
TextView textView = new TextView(this);
textView.setTextSize(40);
textView.setText(message);
// Set the text view as the activity layout
setContentView(textView);
}
And also my Manifest
<?xml version="1.0" encoding="utf-8"?>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".DisplayMessageActivity"
android:label="#string/title_activity_display_message"
android:parentActivityName=".MainActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.example.andreas.myapplication.MainActivity" />
</activity>
</application>
And Gradle Infos
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.example.andreas.myapplication"
minSdkVersion 8
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
iam confused because im alredy use the right method for minSdkVersion 8.
Does anyone know, why ma App does not show the Icon as Up-Button?
best Regards
I have encountered the same problem - enabling "display home as up" led to the Up button with an arrow image on it. I have managed to replace arrow with an app icon with the following steps:
Create a new ImageAsset with app icon images in /drawable.
In OnCreate() of child activity, add 2 lines:
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeAsUpIndicator(R.drawable.ic_action_home);
Substitute meta-data value android:value="com.example.andreas.myapplication.MainActivity" for android:value=".MainActivity"
To support older devices with the support library, also include a element that specifies the parent activity as the value for android.support.PARENT_ACTIVITY as shown below:
<!-- Parent activity meta-data to support 4.0 and lower -->
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity" />
A full explanation is here: http://programmerguru.com/android-tutorial/how-to-add-up-button-on-action-bar/
I believe you need to call getSupportActionBar().setDisplayHomeAsUpEnabled(true); after calling setContentView(textView); in the second activity.
EDIT:
also, main activity should not call getSupportActionBar().setDisplayHomeAsUpEnabled(true); as it leads nowhere. And you should add a button to switch activities or you will never get to DisplayMessageActivity. try something like this:
Intent showmessg = new Intent(getApplicationContext(), DisplayMessageActivity.class);
startActivity(showmessg);
Hope it works for you.
source: http://developer.android.com/training/basics/actionbar/adding-buttons.html#UpNav
I think in android 5 and API 21 we can't use app icon for up action.
if your appcompat support library is v7 rev21 i think you can't use the app icon at least for up action. but u can use it instead of top left caret or you can use app icon right of that caret although if u click it nothing happen.
I have two app completely like that trainings in one of them i use the older appcompat v7 and minSdkVersion="11" and i never added getSupportActionBar().setDisplayHomeAsUpEnabled(true); to it but app have app icon and no problem . but in another app i update my support library a few day ago to rev21 and of course this app's minSdkVersion is "8" but this app hasn't actionBar icon for Up action and if you add top code to it you do nothing.
I search many of sites and just i understand is that in material design google removed app icon for up action because of increasing space on actionbar and etc.
You can see this line in this page.
"When using the Material themes (default in API 21 or newer) the
navigation button (formerly "Home") takes over the space previously
occupied by the application icon. Apps wishing to express a stronger
branding should use their brand colors heavily in the action bar and
other application chrome or use a in place of their standard title
text."
I implement layout for actionbar, including one button and other is setting button. I view in preview window (Intellij IDEA 13) I see as I expected but not on real device (samsung note 3).
Here is my layout:
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<!-- chat list. should appear as action button -->
<item android:id="#+id/action_chat_list"
android:icon="#drawable/ic_menu_chat_list"
android:title="#string/action_chat"
android:showAsAction="ifRoom" />
<!-- Settings, should always be in the overflow -->
<item android:id="#+id/action_settings"
android:title="#string/action_settings"
android:showAsAction="never" />
</menu>
In Preview windows. I see as I expected:
But when I run on real device (Samsung Note 3).I cannot see Setting button:
I cannot understand why. Please tell me how to fix this.
Thanks :)
It because samsung has still a menu button. AFAIK there is no workaround for this
Because you got the options button down to the left of your homebutton. When you thouch it the overflow menu will show on the screen. I guess it implemented in the background so it doenst show on devices that have a "real hardware" options button.
Heres a picture of the button i found on the web. http://cdn.webcazine.com/wp-content/uploads/2012/06/samsung_galaxy_s3_option_keys1.jpg?00d8d4
As #Blackbelt has mentioned, because samsung has a menu button, so actionbar will automatically hide this. And I successfully follow this link to fix this problem. This really a small hack because you use java reflection api to change value of private attribute.
You put this code first when you start to run your application. You can subclass Application and put this code in onCreate
public class MyApplication extends Application {
private static final String TAG = "MyApplication";
private static Context mContext;
#Override
public void onCreate() {
super.onCreate();
mContext = getApplicationContext();
try {
ViewConfiguration config = ViewConfiguration.get(this);
Field menuKeyField = ViewConfiguration.class.getDeclaredField("sHasPermanentMenuKey");
if(menuKeyField != null) {
menuKeyField.setAccessible(true);
menuKeyField.setBoolean(config, false);
}
} catch (Exception ex) {
// Ignore
}
}
}
And you declare this class in your android manifest file under application tag:
<application
android:label="#string/app_name" android:icon="#drawable/ic_launcher" android:allowBackup="true"
android:name=".MyApplication">
</application>
Hope this help :)
I'm trying to do some things on the ActionBar in Android.
I've already added new items in the right side of the action bar.
How can I change the left side of the action bar? I want to change the icon and the text, and I want to add a "Back Button" in the action bar for the other screens
This is very simple to accomplish
If you want to change it in code, call:
setTitle("My new title");
getActionBar().setIcon(R.drawable.my_icon);
And set the values to whatever you please.
Or, in the Android manifest XML file:
<activity android:name=".MyActivity"
android:icon="#drawable/my_icon"
android:label="My new title" />
To enable the back button in your app use:
getActionBar().setHomeButtonEnabled(true);
getActionBar().setDisplayHomeAsUpEnabled(true);
The code should all be placed in your onCreate so that the label/icon changing is transparent to the user, but in reality it can be called anywhere during the activity's lifecycle.
To make a single icon be usable by all your action bars you can do this in your Android Manifest.
<application
android:logo="#drawable/Image">
...
</application>
You just need to add these 3 lines of code. Replace the icon with your own icon. If you want to generate icons use this
getSupportActionBar().setHomeAsUpIndicator(R.drawable.icon_back_arrow);
getActionBar().setHomeButtonEnabled(true);
getActionBar().setDisplayHomeAsUpEnabled(true);
In Android 5.0 material design guidelines discourage the use of icon in actionBar
to enable it add the following code
getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setLogo(R.mipmap.ic_launcher);
getSupportActionBar().setDisplayUseLogoEnabled(true);
credit goes to author of this article
If you want to change the Action bar title just give the following 1 line code in the onCreate() of your Activity
getActionBar().setTitle("Test");
ActionBar actionBar = getSupportActionBar();
actionBar.setTitle(getString(R.string.titolo));
actionBar.setIcon(R.mipmap.ic_launcher);
actionBar.setDisplayShowHomeEnabled(true);
You can change the icon in your by adding whatever icon you want to your respective drawable folders, then changing this line in your AndroidManifest.xml file:
android:icon="#drawable/ic_launcher"
to match whatever the name of your icon is in there. Or put your icon as ic_launcher, if they're the same icon. As for what it says, add or change whatever strings match up to that in your res/values/strings.xml file. Then, once again in your AndroidManifest.xml file, change this line:
android:label="#string/app_name"
to whatever the string you have in their. You'll have to do this for the application as a whole, and whichever activities you want, but the lines are the same.
Hope this helps.
For that, you can do it in 2 ways: XML or Java. See here: How to change the text on the action bar
So:
XML:
<activity android:name=".Hello_World"
android:label="This is the Hello World Application">
</activity>
Java:
public class TitleBar extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final boolean customTitleSupported = requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.main);
if ( customTitleSupported ) {
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.titlebar);
}
final TextView myTitleText = (TextView) findViewById(R.id.myTitle);
if ( myTitleText != null ) {
myTitleText.setText("NEW TITLE");
// user can also set color using "Color" and then "Color value constant"
// myTitleText.setBackgroundColor(Color.GREEN);
}
}
}
For set Title :
getActionBar().setTitle("Title");
For set Icon :
getActionBar().setIcon(R.drawable.YOUR_ICON_NAME);
Add the below code inside an onCreate function in your activity.
setTitle("NewName");
I used the following call inside onNavigationItemSelected:
HomeActivity.this.setTitle(item.getTitle());
Go to manifest in which specific activity you want to change Action bar Title name and write
android:label="Title name"
This work for me:
getActionBar().setHomeButtonEnabled(true);
getActionBar().setDisplayHomeAsUpEnabled(true);
getActionBar().setHomeAsUpIndicator(R.mipmap.baseline_dehaze_white_24);
The action bar title will, by default, use the label of the current activity, but you can also set it programmatically via ActionBar.setTitle().
To implement the "Back" (more precisely, "Up") button functionality you're talking about, read the "Using the App Icon for Navigation" section of the Action Bar developer guide.
Finally, to change the icon, the guide covers that as well. In short, the action bar will display the image supplied in android:icon in your manifest's application or activity element, if there is one. The typical practice is to create an application icon (in all of the various densities you'll need) named ic_launcher.png, and place it in your drawable-* directories.
I got non-static method setTitle(CharSequence) cannot be referenced from a static context error because I used setTitle() in static PlaceholderFragment class. I solved it by using getActivity().getActionBar().setTitle("new title");
You can also do as follow :
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main2)
setSupportActionBar(toolbar)
setTitle("Activity 2")
}
Go to AndroidManifest.xml file.
Find the <application> tag
There you can see a attribute
android:label="#string/app_name"
Now go to res > values > strings.xml
Change the
<string name="app_name">MainActivity</string>
to
<string name="app_name">Your Desired Name</string>
Example
AndroidManifest.xml
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:name=".MainActivity"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".SubmitForm">
</activity>
</application>
strings.xml
<resources>
<string name="app_name">Your Desired Name</string>
<string name="action_settings">Settings</string>
</resources>
I've been having this problem for almost 2 months now and can't figure it out. The problem is that if my application is running and I run (reinstall) my application from Eclipse, I get an error message indicating that my application has crashed 'Unfortunately, has stopped.'. I notice that it also occurs when I run it away from my PC/Eclipse, I think that it happens only after I don't run it for a while.
It only occurs if the app is active in the 3rd activity (BaseDiagramActivity) and then I run the app again from Eclipse. I've stripped out basically all the application except the 3 activities and It's still happening.
I've searched and searched for a solution to this problem but can't find any good answer or one that applies to me.
It doesn't seem like a hardware or android version issue as I'm running this on my tablet (4.0.3) and my phone (4.0.2, was happening on 4.0.1 before update). Unless of course it is an ice cream sandwich bug.
Let me know if any more info is required.
The exception (Tag=AndroidRuntime)
FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to instantiate application android.app.Application: java.lang.NullPointerException
at android.app.LoadedApk.makeApplication(LoadedApk.java:482)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:3938)
at android.app.ActivityThread.access$1300(ActivityThread.java:123)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1185)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4424)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at android.app.LoadedApk.initializeJavaContextClassLoader(LoadedApk.java:362)
at android.app.LoadedApk.getClassLoader(LoadedApk.java:305)
at android.app.LoadedApk.makeApplication(LoadedApk.java:474)
... 11 more
The Android Code
LoadedApk.initializeJavaContextClassLoader() - Line 362 seems to be the offender
Below are the relevant files:
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="[my package]"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="14" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name="HomeActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="LoadDiagramActivity" android:label="Load Diagram"></activity>
<activity android:name="BaseDiagramActivity" android:label="Base Diagram"></activity>
</application>
</manifest>
HomeActivity.java
public class HomeActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.home);
Button diagramButton = (Button)findViewById(R.id.diagram);
diagramButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
startActivity(new Intent(HomeActivity.this, LoadDiagramActivity.class));
}
});
}
}
LoadDiagramActivity.java
public class LoadDiagramActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ActionBar actionBar = getActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater menuInflater = getMenuInflater();
menuInflater.inflate(R.menu.load_diagram_menu, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
finish();
return true;
case R.id.add_new_diagram:
startActivity(new Intent(this, BaseDiagramActivity.class));
return true;
default:
return super.onOptionsItemSelected(item);
}
}
}
BaseDiagramActivity.java
it doesn't actually matter what activity this is, the exception occurs as long as a 'third' activity is started (or clicking the add button on LoadDiagramActivity.
public class BaseDiagramActivity extends Activity {
}
home.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<Button
android:id="#+id/diagram"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Diagram" />
</LinearLayout>
Additional information
When I stripped down my project in order to ask a simpler answer, I moved everything into the package's namespace. In the actual project there are 5 namespaces, they were still present when I was testing with the stripped down version however just not called (as far as I could see).
Here are the packages:
[package] - general logic
[package].activities - all activities and base activities
[package].database - all interaction with the database
[package].models - models for saving/loading data
[package].renderables - objects drawn to a canvas
I have tried to add an `android:sharedUserId' attribute to the manifest and and it seemed to do nothing both times I tried. When I was initially investigating this I came to the conclusion that the shared user id only applied to different projects, not different packages.
Also I don't believe there was any interaction with the database when I stripped everything down. The fact that the 3rd activity could be any activity, even HomeActivity, was something against this theory.
Useful links
stackoverflow: android.app.Application cannot be instantiated due to NullPointerException
GreoCode android.app.LoadedApk on 4.0.1
Possible race condition?
Android issue #25869
Update 1/11/2012
Last couple of days I've jumped back into this project, I created a brand new project in Eclipse Juno (was on Helios before) and transferred everything over manually so that Eclipse and Android tools handled almost all of the Manifest interaction but it's still occurring. I will look at it a bit more over the next few days and update if I find anything.
FYI my new project is targeting the following:
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="15" />
The new project structure also has all the activities in the root package now (ie. [package], not [package].activities). I'm also using the (new?) syntax to show the parent activity:
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="[my package].LoadDiagramActivity" />
It is also still occurring on my now updated Galaxy Nexus running Jellybean 4.1.2.
Try adding one more thing in Manifest file, I am sure you have already tried..
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="[my package]"
android:versionCode="1"
android:versionName="1.0"
android:sharedUserId="com.mj.app" >
It seems like in your project you have multiple PACKAGES, like com.package.p1 , com.package.p2 ,com.package.p3..
And while starting you are in p1 and then moves on to p2 - p3...
and at that time you try to run it again..so the Android gives you error.
If you put 13 in your minSdkVersion, it should work.
Either that, or you need to setDisplayHomeAsUpEnabled(false) in the onCreate() of your other activities.
Both those solutions should work.
Starting at API Level 14 according to the documentation, the setHomeButtonEnabled(true) is no longer done for you by default, and it goes on to say that
Setting the DISPLAY_HOME_AS_UP display option will automatically enable the home button.
So we can infer that setDisplayHomeAsUpEnabled(false) works in a similar way as setHomeButtonEnabled(false)
If I am not mistaken, this only happens when we reinstall the app from Eclipse Run->As. So this is unlikely to happen when a user upgrades through Play. I can say this with confidence since I did notice my app too with this exception during reinstall through Eclipse, but nothing on Crittercism.
To fix this, I worked on resolving memory consumption of my app.
If you only have 1 set of drawables, then change that. Create a drawables-mdpi and copy all the file from that 1 drawables folder (drawables, drawable-ldpi). If you have just 1 set, Android will resize it for its use on bigger screens, thus internally taking up too much memory, and cleanup of this kind of memory (bitmap) is bug prone. Sound crazy, but does wonders. Dont believe me, run it under Heap memory usage watch before and after this change, you will notice that your app is taking 25% less memory for a common scenario.
If you are doing any Bitmap operations, you may want to consider downscaling. Atleast when you are setting options you definitely want to downscale it. Check here and here. Search or downscaleing.
Finally dont forget to bitmap.recycle(); bitmap = null; in your onDestroy and before all System.exit(0).
Android does a lot of background work, and reinstallation is a abrupt cleanup expectation from the app. Memory not cleaned up can cause issues. This exception is one of those internal ones. So dont think of it to be straightforward.
You haven't added the period to the names of your activities in manifest's android:name attributes. Perhaps, this causes the problem.
Wait after your application crashes when u run it second time. The app will launch after the crashing again. This happens sometimes with me. If the same is the case with u dont forget to clean your project everytime before u run it.
By inspecting your code I feel you are skipping to set "setContentView(rid)" in LoadDiagramActivity. Please try setting the view in onCreate().
Hope this will help you.
You need to append "." before the activity name in Menifest.
Like this
<?xml version="1.0" encoding="utf-8"?>
<uses-sdk android:minSdkVersion="14" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name=".HomeActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".LoadDiagramActivity" android:label="Load Diagram"></activity>
<activity android:name=".BaseDiagramActivity" android:label="Base Diagram"></activity>
</application>
I update your menifest's activity. Please check it...
There is nothing wrong with the code you've given us so far. I just tried it in a new project with the package name com.test and it worked flawlessly. The only thing I added in the files were the package declaration. (And I added the load_diagram_menu.xml, of course.)
If possible, it would be great if you could give us access to the complete project. If the project is working on someone else's computer, it's most likely Eclipse or the Android Eclipse plugin-in that are misbehaving. A clean install of Eclipse would solve that. (Though I understand how being offline could make this difficult. :-) )
For this, be sure to have the "Build Automatically" checked when cleaning the project. (Project -> Build Automatically)