android unable to start Main activity in options menu - java

Hi there basically i have created a options menu and have one of the menu items as the home button which essentially calls the home activity Main.java. I have used the code
startActivity(new Intent("org.me.myandroidstuff.Main"));
in a GetHome method. My problem is that when i run this the application crashes because it isnt handled. Now i know this generally means there is some error in the androidmanifest file however i think my coding is okay so im a bit stumped. Here is my androidmanifest.xml code
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.me.myandroidstuff"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" android:allowBackup="false">
**<activity
android:name=".Main"
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=".PetrolPriceActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="org.me.myandroidstuff.PetrolPriceActivity" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".AreaURL"
android:label="#string/app_name" >
<intent-filter>
<action android:name="org.me.myandroidstuff.AreaURL" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
the part highlighted is the code for my main class. Im rather new to android so i imagine its a relatively simple fix but ive looked and i havent found a solution yet. Thanks

change the code to
startActivity(new Intent("android.intent.action.MAIN"));
In manifest file in action you have written
< action android:name="android.intent.action.MAIN" />
while calling the new Intent(String Action), you need to put the same action name.
or you can use different signature of constructor,
change the code to
startActivity(new Intent(this, Main.class);
in place of "this" you can use the appropriate context.

use startActivity(new Intent(getApplicationContext(), Main.class));

Related

Title: How to differentiate sub package and main package name in android?

Problem: I'm developing content display app. Now I want to enable GCM push notification app, for that I downloaded a sample project from
http://www.androidhive.info/2012/10/android-push-notifications-using-google-cloud-messaging-gcm-php-and-mysql/
The sample project is working fine and notification are coming as expected.
Now I copy pasted the following files to my project
1. manifest file
2. xml file
3. values file
4. MainActivity file
I changed the Packagename that I need from the pervious code that I copied but still it is not working. Please guide me which line i should change the packagename of project , where I should use class packagename and in where i should use the project packagename.
It is giving me error because the package name and sub package name are same.
Code:
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<!-- Register Activity -->
<activity
android:name="com.androidhive.pushnotifications.RegisterActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- Main Activity -->
<activity
android:name="com.androidhive.pushnotifications.MainActivity"
android:configChanges="orientation|keyboardHidden"
android:label="#string/app_name" >
</activity>
<receiver
android:name="com.google.android.gcm.GCMBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<!-- Receives the actual messages. -->
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<!-- Receives the registration id. -->
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="com.androidhive.pushnotifications" />
</intent-filter>
</receiver>
<service android:name="com.androidhive.pushnotifications.GCMIntentService" />
</application>
being a newbie in android development, I'm not able to figure out which is the main package name in this code.
Any suggestion would be great!. thanks in advance
We add it like this:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mymain.package"
android:versionCode="1"
android:versionName="1.0" >
Sarthak Mittal is right, but you also need to change your manifest for main activity:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mymain.package"
android:versionCode="1"
android:versionName="1.0" >
<activity
android:name="com.androidhive.pushnotifications.MainActivity"
android:configChanges="orientation|keyboardHidden"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

Why I can not open android manifest class in eclipse?

In eclipse, if you press CTRL and click the method name, you can open declaration or implementation of this method. I want to use this idea to navigate to a class in android manifest.xml.
All other Activity or Service work just fine, but only Receiver does not.
see code below
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.seafile.seadroid2"
android:versionCode="20"
android:versionName="1.0.1"
android:installLocation="internalOnly"
>
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:name="com.seafile.seadroid2.SeadroidApplication"
android:label="#string/app_name"
android:icon="#drawable/ic_launcher">
<receiver android:name=".OSBootReceiver" >
<intent-filter>
<category android:name="android.intent.category.DEFAULT" />
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
<activity android:name="com.seafile.seadroid2.BrowserActivity"
android:label="#string/app_name"
android:theme="#style/Theme.SeafileTheme"
android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:name="com.seafile.seadroid2.sync.CameraUploadService" > </service>
</application>
</manifest>
I checked if the path was right, the class exists in that path, so why can't I click to open that class?
Anyone can help?
Your receiver is not using the full path. Try changing the declaration from:
<receiver android:name=".OSBootReceiver" >
...
</receiver>
to:
<receiver android:name="com.seafile.seadroid2.OSBootReceiver" >
...
</receiver>
I've found that Eclipse will only respond to a ctrl-click in a manifest file if the name is fully qualified.
Controls if all the check are enabled.
see
General > Editors > Text Editors > Hyperlinking preference page.

Convert Android Widget to an App with a Widget

I have an Android widget (it is shown in the list of widgets on the phone, and is not shown in the list of apps). It has a button which launches a pop-up activity.
Now I would like to change the widget so, that it would be both an app (which will be shown in the list of apps on the phone) which will start from that pop-up activity, and a widget (the same as before) which will launch the app (which will consist of that pop-up activity, but will be displayed and treated like an app).
What changes should I make in my manifest file to make the changes described above?
Below is my manifest file:
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#android:style/Theme.Light.NoTitleBar" >
<receiver android:name="myapp.myapp.MyWidgetProvider" >
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
<meta-data
android:name="android.appwidget.provider"
android:resource="#xml/demo_widget_provider" />
</receiver>
<receiver
android:name="myapp.myapp.MyWidgetIntentReceiver"
android:label="widgetBroadcastReceiver" >
<intent-filter>
<action android:name="GET_HELP" />
<action android:name="CHANGE_PICTURE" />
</intent-filter>
<meta-data
android:name="android.appwidget.provider"
android:resource="#xml/demo_widget_provider" />
</receiver>
<activity
android:name="myapp.myapp.MainActivity"
android:label="#string/title_activity_main" >
</activity>
<activity
android:name="myapp.myapp.CardsChoice"
android:label="#string/title_activity_choice" >
</activity>
</application>
The solution was rather simple: I just needed to add a Launcher Activity to the app.
This operation consists of 2 steps:
Adding activity definition as a launcher activity to the Manifest
Example:
<activity
android:name="package.package"
android:label="#string/title_activity_main"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Adding code of the activity (and the layout) to the app.
It is about an class MainActivity and a layout file activity_main.xml

Launcher activity not starting first

The title explains it pretty much, here is the manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="eu.craym.vulcrum.firstgametnb"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".Splash"
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=".StartingPoint"
android:label="#string/app_name" >
<intent-filter>
<action android:name="eu.craym.vulcrum.STARTINGPOINT" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
Yet whenever I run this application, the StartingPoint classed is called first:
[2013-03-09 18:36:40 - FirstGameTNB] Starting activity eu.craym.vulcrum.firstgametnb.StartingPoint on device emulator-5554
Why is this happening? I thought the MAIN and LAUNCHER were supposed to make it so the Splash class gets called first, but this never happens. Note that when I delete the StartingPoint activity, it goes to Splash.
You're right. You may try a clean on your project.
android.intent.action.MAIN: Start as a main entry point, does not
expect to receive data.
Source

Android: How to start an Activity via button?

Noob Android developer here I'm more graphics than code but thought I'd start doing more coding. Anyway, I have some buttons on my main activity page and I want it so when the button is clicked it opens another class/activity. I've tried all the methods I've looked up and something is still not working, when I click the button in the emulator it just doesn't do anything, does't forcestop or anything just nothing, someone point me in the right direction please.
Code from the main page where the button lives:
public class StartingPoint extends Activity {
protected void onCreate(Bundle aim) {
super.onCreate(aim);
setContentView(R.layout.main);
final Button bSL = (Button) findViewById(R.id.bSongList);
bSL.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent SongList = new Intent(StartingPoint.this, SongList.class);
StartingPoint.this.startActivity(SongList);
}
});
}
}
Manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="myname.appname"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="10" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#android:style/Theme.Black.NoTitleBar" >
<activity
android:name=".Splash"
android:label="#string/app_name"
android:theme="#android:style/Theme.Black.NoTitleBar.Fullscreen" >
<intent-filter>
<action android:name="myname.appname.SPLASH" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".StartingPoint"
android:label="#string/app_name" >
<intent-filter>
<action android:name="myname.appname.STARTINGPOINT" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".SongList"
android:label="#string/app_name" >
<intent-filter>
<action android:name="myname.appname.SONGLIST" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
-L
Last 3 lines of logcat just after clicking the button in question.
01-02 21:59:50.473: I/ActivityManager(75): Starting: Intent { cmp=myname.appname/.SongList } from pid 681
01-02 21:59:52.953: I/ActivityManager(75): Displayed myname.appname/.SongList: +2s351ms
01-02 21:59:58.565: D/dalvikvm(348): GC_EXPLICIT freed 8K, 55% free 2591K/5703K, external 1625K/2137K, paused 520ms
Try this:
Intent songList = new Intent(StartingPoint.this, SongList.class);
startActivity(songList);
Are you getting any errors? You need to add every Activity you create in the manifest. If you have two activities and only the Main in the manifest, that could be you problem.
On second thought, I believe your manifest is wrong. Check this. With the Main (Your starting point) and the Menu which is the second one:
<activity android:name="com.activities.Main">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.activities.Menu"></activity>
Try this manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="myname.appname"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="10" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#android:style/Theme.Black.NoTitleBar" >
<activity
android:name=".Splash"
android:label="#string/app_name"
android:theme="#android:style/Theme.Black.NoTitleBar.Fullscreen" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".StartingPoint"
android:label="#string/app_name" >
</activity>
<activity
android:name=".SongList"
android:label="#string/app_name" >
</activity>
</application>
</manifest>
You don't need to add the filter on each activity. I understood that you have only one entry Activity and that is the splash screen. However, you might need to change the manifest to change the ".Splash" and every other Activity to the full path including the package.
// whats your package name for your SongList
as your log cats shows
01-02 21:59:50.473: I/ActivityManager(75): Starting: Intent { cmp=myname.appname/.SongList } from pid 681
01-02 21:59:52.953: I/ActivityManager(75): Displayed myname.appname/.SongList: +2s351ms
//use full package name in your activity in manifest.xml
<activity
android:name="myname.appname.SongList"
android:label="#string/app_name" >
</activity>
Your activity does not start because it has a NullPointerException in it. (Line 10). When you do a findViewById on something that is not in your layout, most likely.
When facing this kind of problems, reading the red lines is usually helpful. It basically says: "Hey! you have a null object in SongList line 10 when you try to start it!"
Edit
ImageView ivlogo = (ImageView) findViewById(R.id.ivsonglogo);
ExpandableListView elv1 = (ExpandableListView) findViewById(R.id.elv1);
This can never work. This is done during the object initialization, much before onCreate is called, therefore much before you have called setContentView.
You must initialize your widgets after having set the view.
Intent SongList = new Intent(StartingPoint.this, SongList.class);
startActivity(SongList);
and in Manifest type this
<application .....>
<activity android:name=".CustomSurfaceView"></activity>
</application>
For the code try this:
Intent songListIntent = new Intent(this, SongList.class);
StartingPoint.this.startActivity(songListIntent);
And for manifest:
<activity android:name=".SongList"></activity>

Categories