I've got problems with using the Intent object of Android.
I'm basically trying to launch another activity:
My Activity, MapActivity, makes use of a MapEventListener, which provides functions to listen to events based on a map which is rendered in the MapActivty Activity. If a marker is pressed on the map, a function of the MapEventListener is Launched.
I this function I'm trying to implement an Intent object which launches another activty.
This is the function's code:
#Override
public void onVectorElementClicked(VectorElement arg0, double arg1,
double arg2, boolean arg3) {
Intent intent = new Intent(MapActivity.this, DetailPerspectiveActivity.class);
activity.startActivity(intent);
}
This is the manifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.hsrw.landschaftsbilder"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/><application android:icon="#drawable/icon" android:label="#string/app_name" android:allowBackup="false">
<activity android:name=".activities.MapActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name=".activities.GraphhopperRouteTestActivity">
</activity>
<activity android:name=".activities.DetailPerspectiveActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
I'm pretty sure the problem is about "MapActivity.this" but if I change this to MapActivity.this in the manifest the code is still not compilable. That's what eclipse says about the first argument:
No enclosing instance of the type MapActivity is accessible in scope
Thanks in advance!
In your activity, try to change Intent intent = new Intent(.activities.MapActivity.this, .activities.DetailPerspectiveActivity.class); to Intent intent = new Intent(MapActivity.this, DetailPerspectiveActivity.class); (ie. both MapActivity and DetailPerspectiveActivity).
Your manifest.xml file contains problems. you have declared two activities as launcher which will not work
amend manifest.xml code as following.
Instead of following
<activity android:name=".activities.MapActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name=".activities.GraphhopperRouteTestActivity">
</activity>
<activity android:name=".activities.DetailPerspectiveActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
Use the following code
<activity android:name=".activities.MapActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name=".activities.GraphhopperRouteTestActivity">
</activity>
<activity android:name=".activities.DetailPerspectiveActivity">
</activity>
Edit:
What does this line do in your code.
Intent intent = new Intent(.activities.MapActivity.this, .activities.DetailPerspectiveActivity.class);
It usually is the following way
Intent intent = new Intent(FIRST_ACTIVITY.this, SECOND_ACTIVITY.class);
in your case I presume it should be
Intent intent = new Intent(MapActivity.this, DetailPerspectiveActivity.class);
Related
Iam trying to add Splash screen to my existing Android Project, which is not MainActivity.Java, but by default Android Studio is executing MainActivity.Java first, So I want to change the Activity Priority so that my SplashActivity.Java will execute first and later Activity's will follow after the Splash Screen.
Make splash activity your launcher activity instead of Main Activity in Android Manifest.
<activity
android:name=".ui.splash.SplashActivity"
android:screenOrientation="portrait"
android:theme="#style/SplashTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
modify your AndroidManifest.xml like this
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.circlefil.reactivetrip">
<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"/>
<activity android:name=".SplashActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>
You need to add IntentFilter in you splash screen activity and from splash screen activity you have to link your main activity using Intent.
Add following code to your splash screen activity.
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
How ever keeping an entire activity is not the best way to create splash screen. See this for more info: Here
To Start activity first you need to make it Launcher Activity in AndroidManifest.xml file.
<activity
android:name=".StartingActivityName">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
I am very new to writing android app, I am trying to start specific activity from an other app (App B)through my app (App A). I know how to launch the App B but I need App B do some specific task with a click of button without showing the launching process I just want to jump to that task(like playing music with out showing the introduction and starting part of App B).
This is part of App A , the place I want to do specific task from App B instead of just launching it. ( even maybe I don't need to launch it )
public void playOn(View view) {
ImageButton sound = (ImageButton) findViewById(R.id.musicButton);
if (lightt) {
sound.setImageResource(R.drawable.play_dn);
lightt = false;
} else {
sound.setImageResource(R.drawable.play_up);
lightt = true;
}
Intent intent = getPackageManager().getLaunchIntentForPackage("com.Zample.RUNiBplayMusic");
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
}
and this is part of App B that I have access to
<application android:icon="#drawable/ic_launcher" android:label="Bplay Music" android:name="com.Zample.RUNiBplayMusic.Common.App" android:theme="#style/AppTheme">
<activity android:launchMode="singleTask" android:name=".StartActivity" android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data android:host="com.bplaymusicwifi" android:scheme="bplaymu"/>
</intent-filter>
</activity>
<activity android:finishOnTaskLaunch="true" android:name=".HelpListActivity" android:screenOrientation="portrait"/>
<activity android:launchMode="singleTask" android:name=".DeviceListActivity" android:screenOrientation="portrait"/>
<activity android:finishOnTaskLaunch="true" android:name=".PlayModeActivity" android:screenOrientation="portrait"/>
<activity android:finishOnTaskLaunch="true" android:name=".HelpListActivity" android:screenOrientation="portrait"/>
<receiver android:label="Bplay Music" android:name=".AppWidget.AppWidgetSmall">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE"/>
</intent-filter>
<receiver android:label="Bplay Music" android:name=".AppWidget.AppWidgetBig">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE"/>
</intent-filter>
<meta-data android:name="android.appwidget.provider" android:resource="#xml/widget_info_big"/>
</receiver>
<service android:name=".AppWidget.Bplay MusicService"/>
<service android:name=".Record.RecordService"/>
</application>
I think this part of the code from App B might help me. but I am not sure.
I hope you can help me how to solve this issue.
I'm new to Android app development so please be patient with me. I'm writing an app that gets the GPS location from Google Play services and then broadcasts the data over Bluetooth. I have a LocationActivity that gets the location, and an AdvertiseActivity that broadcasts the data.
My problem is that I'm having a hard time understanding the file structure in android apps, so I suspect my lack of understanding is why I'm getting the error.
Here is a snippet of LocationActivity where the error is:
#Override
public void onLocationReceived(Location location) {
Intent i = new Intent(LocationActivity.this, AdvertiseActivity.class) //problem is here
.putExtra("latitude", location.getLatitude());
startActivity(i);
}
Why can't the compiler find AdvertiseActivity.class? Is something wrong with my manifest below?
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme"
tools:ignore="AllowBackup,GoogleAppIndexingWarning">
<activity android:name="com.android.app.LocationActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.android.app.AdvertiseActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
Please help. Thanks!
You are using two activities as MAIN .From manifest, Remove:
<action android:name="android.intent.action.MAIN" />
<action android:name="android.intent.action.DEFAULT" />
From AdvertiseActivity's activity tag. Hope this helps.
Remove these lines from manifest
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
And keep only this line.
<activity android:name="com.android.app.AdvertiseActivity"/>
An Application can have only one android.intent.action.MAIN in Startup Activity. In your LocationActivity you already defined so remove intent-filter from AdvertiseActivity.
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
so its like
<activity android:name="com.android.app.AdvertiseActivity"/>
I created a splash screen in my application suddenly when I ran the code it stopped. I created a splash screen in my code then it will redirect you to the menu. Is there something wrong with the android manifest xml?
Here's my manifest code:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.kenneth.rusa">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
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=".WelcomeActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.action.LAUNCHER">
</category>
</intent-filter>
</activity>
<activity android:screenOrientation="landscape" android:name=".Play">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>
And this is the splash class code:
package com.example.kenneth.rusa;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.SystemClock;
/**
* Created by Kenneth on 8/6/2016.
*/
public class WelcomeActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.welcomeactivity);
RunMe runme = new RunMe();
Thread t = new Thread(runme);
t.start();
}
class RunMe implements Runnable {
public void run() {
SystemClock.sleep(3000);
Intent intent = new Intent(WelcomeActivity.this,MainActivity.class);
startActivity(intent);
finish();
}
}
}
Please remove following lines from activities other than splash
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
Nvm I fixed it by changing the manifest file
Here's the updated code
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.kenneth.rusa">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/Theme.AppCompat.NoActionBar">
<activity android:screenOrientation="landscape" android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.default" />
</intent-filter>
</activity>
<activity android:name=".WelcomeActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:screenOrientation="landscape" android:name=".Play">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.default"/>
</intent-filter>
</activity>
</application>
I am having a bit of an issue here, my code seems right, but its not doing what I am expecting it too.
I have an app and I would like to run when the device boots up. But when the device boots up, it application does not run, which is what I am expecting.
First in my Manifest, I added the uses-permission for RECEIVE_BOOT_COMPLETED:
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
Then also in my Manifest I added a receiver and activity inside the application:
<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>
<receiver
android:name=".BootReceiver"
android:enabled="true"
android:permission="android.permission.RECEIVE_BOOT_COMPLETED" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
<activity
android:name=".BootReceiver"
android:label="#string/title_activity_boot_receiver" >
</activity>
</application>
And then I created a BootReceiver Activity that looks like this:
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
public class BootReceiver extends BroadcastReceiver{
#Override
public void onReceive(Context context, Intent intent) {
Intent i = new Intent(context, MainActivity.class);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
}
}
When I install the app, boot the device, the app does not run right when the device boots up.
I do not understand what I am doing wrong here. Is my code wrong? Anyone got any ideas?
BootReceiver is not your Activity it is class which extends broadcast receiver.
update your manifest, this will be enough
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<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>
<receiver
android:name=".BootReceiver"
android:enabled="true"
>
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
/>
</intent-filter>
</receiver>
</application>
Step #1: Get rid of <activity android:name=".BootReceiver" ..., as you do not have an Activity named BootReceiver.
Step #2: Get rid of <category android:name="android.intent.category.DEFAULT" />, as categories are not usually used on broadcasts, and definitely is not used here.
Step #3: Get rid of android:permission="android.permission.RECEIVE_BOOT_COMPLETED", as that indicates that the sender of the broadcast must hold that permission, which may not be true.
You will be looking to have a manifest that looks more like:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.commonsware.android.sysevents.boot"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk
android:minSdkVersion="7"
android:targetSdkVersion="11"/>
<supports-screens
android:largeScreens="false"
android:normalScreens="true"
android:smallScreens="false"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name">
<receiver android:name=".OnBootReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
</receiver>
<activity
android:name="BootstrapActivity"
android:theme="#android:style/Theme.NoDisplay">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>
(from this sample app)
That's strange 'cause all you mentioned with Manifest and code seems good...
So do you mean no MainActivity is running after Boot?
BTW I used this in my Manifest and works fine:
<receiver
android:name="com.example.BootMeUp"
android:enabled="true"
android:permission="android.permission.RECEIVE_BOOT_COMPLETED" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
Try this: This code works for me....
<receiver
android:name="your.package.name.BootReceiver"
android:permission="android.permission.RECEIVE_BOOT_COMPLETED">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>