MapActivity launching from OnClickListener - android

Just started working with android and ran into a small problem. I am have a TabActivity that is loading 3 other Activity classes. This works great. I then have a button on the other Activity classes that I would like to launch a MapActivity. When I do that I keep getting a Force Close.
I googled but I cannot figure out if it is the manifest file or something else. The idea is the tabs are showing location information and you click a button to plot it on the map and get directions.
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.location_tab);
...
Button btnMap = (Button) findViewById(R.id.btnLaunchMap);
btnMap.setOnClickListener(mMapListener);
}
private OnClickListener mMapListener = new OnClickListener() {
public void onClick(View v) {
Intent mapIntent = new Intent(getApplicationContext(),LocationMap.class);
startActivity(mapIntent);
}
};
If I launch any other activity it works but not launching the mapactivity. If I take the mapactivity class and put it in a new project it works.
My manifest
<uses-permission android:name="android.permission.INTERNET" />
<application android:icon="#drawable/icon" android:label="#string/app_name">
<activity android:name=".Splash"
android:label="#string/app_name"
android:theme="#android:style/Theme.NoTitleBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Locations"
android:label="#string/app_name"
android:theme="#android:style/Theme.NoTitleBar"></activity>
<activity android:name=".LocationNewYork"
android:label="#string/app_name"
android:theme="#android:style/Theme.NoTitleBar">
</activity>
<activity android:name=".LocationChicago"
android:label="#string/app_name"
android:theme="#android:style/Theme.NoTitleBar"></activity>
<activity android:name=".LocationSeattle"
android:label="#string/app_name"
android:theme="#android:style/Theme.NoTitleBar"></activity>
<activity android:name=".LocationMap"
android:label="#string/app_name"
android:theme="#android:style/Theme.NoTitleBar">
</activity>
<uses-library android:name="com.google.android.maps"/>
</application>
thougths?

<action android:name="android.intent.action.MAIN" />
inside of the mapactivity's instance ACTIVITY field in the Manifest file does it.
So if you have a MapActivity named QMap, the following code in the Manifest actually works:
<activity android:name=".QMap"><action android:name="android.intent.action.MAIN" /></activity>
Hope it helped

I had the same problem, wanted to launch map activity from an other activity over onClick-event, the problem was: errors in the MapActivity
If you are using eclipse try to run "debug as" without setting any breakpoints

Related

"App has stopped" when changing between activities

Hello everyone this is my first android coding and im trying to switch between activities, but i cant simply find where is my mistake.
Main here;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
protected void start()
{
Intent k= new Intent(MainActivity.this, Try.class);
startActivity(k);
finish();
}
And My manifest is here and my second activity name is "Try";
<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="com.example.ege.intent.Try"
android:label="#string/app_name" >
</activity>
</application>
Thanks.
I think;
May your class package name is wrong but there should be more information about crash.
Change android:name="com.example.ege.intent.Try"
with Try.class location, if it is same in Manifest.
Just try to Change android:name=".Try"
If you put your error or your log details, I can help you
the method "start()" is unused. use it in "onCreate()" method .
you may add a button . swtich activities by listening the click.
Where do you call start()?. Manifest seems okay but check if your package is right, anyway try would do the same, MainActivity lacks a closing semicolon }

No activity found to handle Intent/no launcher activity found manifest file issue

Here's the problem guys, first i tried to run my application with Launch default activity as launch action (Run Configurations --> Android --> Launch action), the logcat kept telling me that it can't find the launcher activity and the application wouldn't even start, problem is i defined my launcher activity in the manifest file, but it's like it's not reading it at all.
So i tried to launch the splash activity by specifically telling it to run it through run configurations, it did launch but during the transition to the next activity it crashed again, the logcat says no activity found to handle intent, which again, I defined the way I did in other applications and worked alright there. Plase help it's a nightmare.
Here's the code for the MainActivity:
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Thread timer = new Thread()
{
public void run(){
try{
sleep(6000);
} catch (InterruptedException e){
e.printStackTrace();
} finally {
Intent openStarting = new Intent("totaltrainer.com.WorkoutPlace");
startActivity(openStarting);
}
}
};
timer.start();
}
#Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
finish();
}
}
And Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="totaltrainer.com"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<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="totaltrainer.com.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".WorkoutPlace"
android:label="#string/app_name" >
<intent-filter>
<action android:name="totaltrainer.com.WorkoutPlace" />
</intent-filter>
</activity>
<activity
android:name=".WorkoutHome"
android:label="#string/app_name" >
<intent-filter>
<action android:name="totaltrainer.com.WorkoutHome" />
</intent-filter>
</activity>
<activity
android:name=".WorkoutGym"
android:label="#string/app_name" >
<intent-filter>
<action android:name="totaltrainer.com.WorkoutGym" />
</intent-filter>
</activity>
</application>
</manifest>
use "totaltrainer.com.WORKOUTGYM" and so on
and below use this
<category android:name="android.intent.category.DEFAULT" />
Problem 1
logcat kept telling me that it can't find the launcher activity and
the application wouldn't even start
In your Manifest file, change below
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="totaltrainer.com.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
as
<activity android:name="MainActivity">
<!-- This activity is the main entry, should appear in app launcher -->
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
What happens when you define this Action and Category ?
The ACTION_MAIN action indicates this is the main entry point and does not expect any intent data.
The CATEGORY_LAUNCHER category indicates that this activity's icon should be placed in the system's app launcher. If the element does not specify an icon with icon, then the system uses the icon from the element.
These two must be paired together in order for the activity to appear in the app launcher.
Problem 2
the logcat says no activity found to handle intent
Your Manifest declaration seems fine.
In your activity class, change
Intent openStarting = new Intent("totaltrainer.com.WorkoutPlace");
startActivity(openStarting);
as
Intent openStarting = new Intent();
openStarting.setAction("totaltrainer.com.WorkoutPlace");
startActivity(openStarting);

Application starting with different activity, Android Studio

first timer here (both in development and posting in SO). I've used idunnololz to create an animated listview for a simple reference app I'm trying to make. It's turned out really well, but after I've created it, when I run the app to test it, it now runs as AnimatedExpandableListView both in the ActionBar title and in the app drawer. I've searched here and found that you can get the app to launch with a different activity by editing the AndroidManifest.xml, so I verified that I'm pointing to my MainActivity class:
<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>
</application>
I presume this may be an issue with the MainActivity class, but maybe there's something here that I'm missing?
I found my answer here:
Android: App name shows the first page name, not the app name
<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 **NEED #string/app_name HERE**>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

Android launch other activity before launching splash activity

I'm developing an application in android, where the app starts with a splash screen. I declared the splash activity as launcher activity in the manifest, but when I start my app, the launcher always shows up a grey activity with no content instead of the actionbar with the title of my app. The splash activity always comes up after one or two seconds.
Can anyone explain this behavior to me?
Here's my manifest:
<application
android:allowBackup="true"
android:hardwareAccelerated="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:logo="#drawable/navigation"
android:theme="#style/Theme.Sherlock.Light" >
<activity
android:name="de.test.basic.SplashActivity"
android:launchMode="singleTask"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity></application>
And here's the onCreate() method of the SplashActivity:
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.spash_screen);
img = (ImageView) findViewById(R.id.imageView1);
img.setImageResource(R.drawable.splashscreen);
getActionbar().hide();
slideMenu.setSlidingEnabled(false);
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
startActivity(new Intent(SplashActivity.this,
OtherActivity.class));
overridePendingTransition(android.R.anim.fade_in,
android.R.anim.fade_out);
finish();
}
}, SPLASH_DELAY);
}
Thanks for any help :)
Looks like its a bug in the api!
Simply add this in your starter activity declared in your manifest:
<activity
...
android:theme="#style/Theme.NoActionBar" >
<intent-filter>
...
</intent-filter>
</activity>
And if you are using ActionBarSherlock
<activity
...
android:theme="#style/Theme.Sherlock.NoActionBar" >
<intent-filter>
...
</intent-filter>
</activity>
Your question is rather similar than this one

Why is my app launching the wrong activities?

I have play buttons on custom popups and they are taking me to the wrong activity and im not sure why. The activity its launching is not even in the onclick method.
Button playit = (Button) dialog.findViewById(R.id.playDetourDialog);
playit.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
System.out.println("go to pyramid");
Intent i = new Intent(getApplicationContext(), PyramidGamePlay.class);
startActivity(i);
dialog.dismiss();
}
});
manifest:
<?xml version="1.0" encoding="utf-8"?>
<application android:icon="#drawable/icon" android:label="#string/app_name">
<activity android:name=".Main"
android:label="#string/app_name" android:theme="#android:style/Theme.NoTitleBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:theme="#android:style/Theme.NoTitleBar" android:name="GamePlayRegular"></activity>
<activity android:theme="#android:style/Theme.NoTitleBar" android:name="WorldSelect"></activity>
<activity android:theme="#android:style/Theme.NoTitleBar" android:name="OptionsPage"></activity>
<activity android:theme="#android:style/Theme.NoTitleBar" android:name="World"></activity>
<activity android:name="GameEndPage" android:theme="#android:style/Theme.NoTitleBar"></activity>
<activity android:theme="#android:style/Theme.NoTitleBar" android:name="PyramidGamePlay"></activity>
</application>
Use like this
<activity android:name="PyramidGameplay">
<intent-filter>
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
It's hard to know without more information. Have you defined your activity in your AndroidManifest.xml? What info does logcat print when you tap the playit button?
It would also be good to use the android.util.log package for logging, rather than using System.out.println.

Categories

Resources