I'm developing an Android tablet application containing lots of activities that use the Theme.Holo.DialogWhenLarge theme. On real devices (Nexus 7 KitKat and Samsung Galaxy Tab 3 8") these activities are displayed as expected, but on every Genymotion VM I try to create (Nexus 7 KitKat and Nexus 10 Jelly Bean for example) they are displayed as normal full-screen activities. I tested also on a Nexus 7 KitKat emulator created with the standard Android SDK Virtual Device Manager, and activities are displayed as expected.
I can ignore it and suppose that it's only a problem with the Genymotion emulator, but I want to know if there's a way to fix that in order to have a better test environment. I would like to point out that the *-large resource qualifier works on the Genymotion VMs, the issue looks related only to that theme.
To reduce all possible causes of the problem I created a new test project with a normal main activity having a button that launches a DialogWhenLarge-themed activity. I also removed all Android support libraries and all XML styles files automatically created by Eclipse: the only resources left are the two layouts for the activities and the launcher icon. These are all the files of the test project:
src/com/example/testdialogwhenlarge/MainActivity.java
package com.example.testdialogwhenlarge;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
public class MainActivity extends Activity {
#Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
findViewById(R.id.button).setOnClickListener(new View.OnClickListener() {
#Override public void onClick(View v) {
// Start the DialogWhenLarge-themed activity
startActivity(new Intent(MainActivity.this, TestActivity.class));
}
});
}
}
src/com/example/testdialogwhenlarge/TestActivity.java
package com.example.testdialogwhenlarge;
import android.app.Activity;
import android.os.Bundle;
public class TestActivity extends Activity {
#Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test);
}
}
res/layout/activity_main.xml
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.testdialogwhenlarge.MainActivity">
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
</FrameLayout>
res/layout/activity_test.xml
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.testdialogwhenlarge.TestActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
</FrameLayout>
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.testdialogwhenlarge"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="19" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="TestDialogWhenLarge"
android:theme="#android:style/Theme.Holo">
<activity android:name="com.example.testdialogwhenlarge.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.example.testdialogwhenlarge.TestActivity"
android:theme="#android:style/Theme.Holo.DialogWhenLarge">
</activity>
</application>
</manifest>
This issue has been fixed by the Genymotion team in release 2.3.0.
Related
Initially my Android project had only one activity named MainActivity. Then, I added a new activity named ChildActivity into my project. I'm trying to launch my new activity as startup activity when app gets launched. I changed AndroidManifest.xml file to achieve it. I moved the entire intent-filter tag from MainActivity to ChildActivity as shown below:
<activity android:name=".MainActivity">
</activity>
<activity android:name=".ChildActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Layout file of ChildActivity looks like this. I'm trying to show a TextView on the new activity I've just added:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ChildActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/tv_display"
android:text="Hello this is Rasik!"/>
</android.support.constraint.FrameLayout>
ChildActivity.java file:
package com.example.android.explicitintent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;
public class ChildActivity extends AppCompatActivity {
private TextView mDisplayText;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_child);
}
}
Whenever I try to debug my app in Android AVD, nothing happens. It seems my app is crashing at start up. Can anyone help me in diagnosing the root cause?
The class android.support.constraint.FrameLayout not exists. Try LinearLayout, FrameLayout, android.support.constraint.ConstraintLayour or others
please try this !
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/tv_display"
android:text="Hello this is Rasik!"/>
</FrameLayout>
i think there is issue with root framelayout
You used wrong layout.
Just convert android.support.constraint.FrameLayout to FrameLayout.
Or convert to default android.support.constraint.ConstraintLayout
<FrameLayout
...>
<TextView
...
/>
</FrameLayout>
The Root layout android.support.constraint.FrameLayout you are using does not exist. Check out this link Android Developer guide.
Your Root layout can be:
FrameLayout
LinearLayout
RelativeLayout
ConstraintLayout
There are many layouts available which you can use based on your need.
I had seen a similar issue in another post. Just off the bat, it seems like your child activity is not within the enclosing terms of the ".MainActivity."
Put the child activity into the brackets of the ".MainActivity", in between the
<activity android:name=".MainActivity"> </actvitiy>. Hopefully that makes it run better. If that doesn't work, start the child activity during the onCreate() method of the MainActivity.
My simple android to print hello world is not running properly. Android virtual Device is getting start but not showing any output. Here is my code plz fix it.
its my java class.
package com.example.jack;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
here is mainActivity.xml for layout.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/hello_world" />
</LinearLayout>
And here is String.xmm.
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">jack</string>
<string name="action_settings">Settings</string>
<string name="hello_world">Hello World</string>
</resources>
here is AndroidMenifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.jack"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.jack.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>
</application>
Avd is showing only the android image. Nothing more.. Plz help me out.
AVD showing only the android image and nothing else loading after a reasonable period of time likely means that your system is unable to render the resolution that you have chosen (Note that I said most likely - in some cases, I have found that AVD takes like 15 minutes just to start but then runs properly after that). A solution to this would be to check the 'Use Host GPU' option under Emulation options.
If that does not solve it, try to reduce the Memory and VM heap options. That should most certainly solve it.
If you are unable to start the app on a physical device as well, then it likely means there is an error in your app.
The AVD can take a while to start up the first time depending on the machine resources and does stay on the Android Logo for some time. It should always boot up completely through. If there is an error with your app it will show you an alert saying your app has stopped working. Just give it some time to boot completely.
I have two activities that I want this navigation to happen, they are VendorsActivity and QuestionsActivity. The following how my AndroidManifest.xml looks like:
(I am not using the full name of my activities like com.hello.world.MyActivity as I am defined package attribute in manifest node.)
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="19" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".VendorsActivity"
android:label="#string/vendors_activity_title" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".TestsActivity"
android:label="#string/tests_activity_title"
android:parentActivityName=".VendorsActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".VendorsActivity" />
</activity>
<activity
android:name=".QuestionsActivity"
android:label="#string/questions_activity_title" >
</activity>
</application>
And in TestsActivity, I am calling getActionBar().setDisplayHomeAsUpEnabled(true); method from within onCreate method.
The problem is, it won't work unless I implement the following method in .TestsActivity class:
#Override
public boolean onOptionsItemSelected(MenuItem item)
{
switch (item.getItemId())
{
case android.R.id.home:
NavUtils.navigateUpFromSameTask(TestsActivity.this);
return true;
default:
return super.onOptionsItemSelected(item);
}
}
But Android Developer Guide says that I don't have to handle the Up button's event as mentioned at the very bottom of hit page: https://developer.android.com/training/basics/actionbar/adding-buttons.html
Because the system now knows MainActivity is the parent activity for
DisplayMessageActivity, when the user presses the Up button, the
system navigates to the parent activity as appropriate—you do not need
to handle the Up button's event.
Edit and Answer:
As Android Developer Guide says:
Beginning in Android 4.1 (API level 16), you can declare the logical
parent of each activity by specifying the android:parentActivityName
attribute in the element.
If your app supports Android 4.0 and lower, include the Support
Library with your app and add a element inside the
. Then specify the parent activity as the value for
android.support.PARENT_ACTIVITY, matching the
android:parentActivityName attribute.
So I think my problem was because of two reasons:
Running the app on a proper emulator. I was targeting a higher version but the emulator was running on API 14 (Android 4.0) so it didn't know how to handle android:parentActivityName attribute.
Targeting the right API level in Project Build Target properties as shown below:
If you receive an error similar to
E/NavUtils﹕ getParentActivityIntent: bad parentActivityName
or
does not have a parent activity name specified. (Did you forget to add the android.support.PARENT_ACTIVITY <meta-data> element in your manifest?)
You will probably need to change android:value to the full path.
So instead of
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity" />
do
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.package.SecondActivity" />
android:parentActivityName attribute supported only after API level.
One alternative is using support-library:v7 combined with NavUtils.
There is a great training material about this topic (include compatibility issue).
please check
- http://developer.android.com/training/implementing-navigation/ancestral.html
That being said, i am posting my code below because it is working :-
MainActivity.Java
package com.example.activitydatasend;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button click = (Button) findViewById(R.id.click);
click.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent intent = new Intent(MainActivity.this,Second.class);
intent.putExtra("first", "first");
intent.putExtra("second", "second");
startActivity(intent);
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
SecondActivity.java
package com.example.activitydatasend;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
public class Second extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.second);
Bundle bundle = getIntent().getExtras();
String a = bundle.getString("first");
String b = bundle.getString("second");
System.out.println(a+b);
getActionBar().setDisplayHomeAsUpEnabled(true);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
AndroidManifext.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.activitydatasend"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="18" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.activitydatasend.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="com.example.activitydatasend.Second"
android:label="#string/app_name"
android:parentActivityName="com.example.activitydatasend.MainActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/click"
android:text="Click" />
</RelativeLayout>
second.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Second Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
</RelativeLayout>
you can add metadata in manifest to support pre JellyBean OS.
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".VendorsActivity" />
What API version are you using? In my experience, for older versions it is necessary to handle the up button event yourself, whereas with later versions it's done for you.
I haven't looked into which exact version changes this, but I know that API 13 doesn't handle it for you, while API 16 does.
I'm new to Android programming and i'm doing tutorial from layouts from http://developer.android.com/resources/tutorials/views/index.html . Relative layout tutorial exactly. I did everything they say but when I try to start app in android emulator there are no buttons, textfields etc. Only name of app shows at the top. What is wrong? Is this a problem with emulator? I'm using Eclipse Version: 3.7.1.
EDIT:
package pchot.tutorial;
import android.app.Activity;
import android.os.Bundle;
public class Tutorial1Activity extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="pchot.tutorial"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="7" />
<application android:icon="#drawable/icon" android:label="#string/app_name">
<activity android:name=".Tutorial1Activity"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
Layout is copy/paste from http://developer.android.com/resources/tutorials/views/hello-relativelayout.html
EDIT:
Ok, problem solved. I needed to delete "Hello World, Tutorial1Activity!" from string.xml file which was autocreated during creation of project in Eclipse.
Have you modified you manifest.xml file? Maybe you haven't modify it to make it aware that the launched main activity is the activity you've just created.
You didn't declare anything in your onCreate() method.
For Button declare Button btn = (Button)findViewById(R.id.btnSubmit)
Implement onClickListener if you want the button to listen to clicks.
For TextView, declare TextView tv = (TextView)findViewById(R.id.textview)
I've made a very simple app that just displays a Google map. However, it only seems to be displaying gray squares.
I've troubleshooted and have done virtually everything I could. I checked my code 5+ times over, I've compared it even to other tutorials. I've re-made my API key 3 times - none of them work.
The phone I'm using is connected to wireless. Even the emulator won't work. I have the library and permission established in the manifest. I think I've done just about everything, but it still doesn't work... any suggestions?
Here's my code:
MapsActivity.java:
package net.learn2develop.GoogleMaps;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;
import android.os.Bundle;
public class MapsActivity extends MapActivity
{
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
#Override
protected boolean isRouteDisplayed() {
return false;
}
}
main.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<com.google.android.maps.MapView
android:id="#+id/mapView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:enabled="true"
android:clickable="true"
android:apiKey="0duU2_tgS67qkUZIpmLVIo0IDvJDh4Ew1Mzh9Pg"
/>
</RelativeLayout>
GoogleMapsManifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="net.learn2develop.GoogleMaps"
android:versionCode="1"
android:versionName="1.0.0">
<uses-sdk android:minSdkVersion="7" />
<application android:icon="#drawable/icon" android:label="#string/app_name">
<uses-library android:name="com.google.android.maps" />
<activity android:name=".MapsActivity"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-permission android:name="android.permission.INTERNET" />
</manifest>
You need to add
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
into you manifest
Note: If you are using both NETWORK_PROVIDER and GPS_PROVIDER, then you need to request only the ACCESS_FINE_LOCATION permission, because it includes permission for both providers. (Permission for ACCESS_COARSE_LOCATION includes permission only for NETWORK_PROVIDER.)
The problem was that Mike was using an API key generated with the release keystore instead of the debug keystore that eclipse uses when compiling the apk.
I had the same error ! I tried everything, so a try this tutorial below and it worked!!!!
TUTORIAL