android projects pulling from each other in eclipse - android

I have two projects with similar starting splash and menu activities, but the package name is different. When I run my latest project it is pulling the other menu activity from the other project. Is this something i've screwed up in naming something? I checked my Manifest and everything appears to be correct. Anyone had this happen before?
Manifest:
<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=".Menu"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MENU" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
Activity:
package com.****.tools;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
public class Splash extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
Thread timer = new Thread(){
public void run(){
try{
sleep(3000);
}catch (InterruptedException e){
e.printStackTrace();
}finally{
Intent openMainMenu = new Intent("com.*****.MENU");
startActivity(openMainMenu);
}
}
};
timer.start();
}
}
package com.****.tools
import android.app.Activity;
import android.os.Bundle;
public class Menu extends Activity{
#Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.menu);
}
}

You are opening the actitty using action but not defined in new manifest so it is taking from the old
Intent openMainMenu = new Intent("com.*****.MENU");//<---------
startActivity(openMainMenu);
Note the new Action name should be differ from old one other wise it will so a select dialog having both activity in that.
<activity
android:name=".Menu"
android:label="#string/app_name">
<intent-filter>
<action android:name="com.*****.MENU_NEW" />
<action android:name="android.intent.action.MENU" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
Intent openMainMenu = new Intent("com.*****.MENU_NEW");//<---------
startActivity(openMainMenu);

Related

How to add an activity before MainActivity.java

How do you add an activity (SplashActivity.java in my case) that launches automatically before the MainActivity? I've added in the below code but the activity is still being skipped over. I've already tried going to Edit Configurations -> Launch -> Default Activity. And the Splash Activity is the only activity with an intent filter.
SplashActivity.java
package com.example.simplesplashscreen;
import android.app.Activity;
import android.content.Intent;
import android.graphics.drawable.AnimatedVectorDrawable;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.util.Log;
import androidx.appcompat.widget.AppCompatImageView;
public class SplashActivity extends Activity implements InterfaceSplash {
private AppCompatImageView image;
private AnimatedVectorDrawable animation;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
image = (AppCompatImageView) findViewById(R.id.splashobject);
launchSplashScreen();
dismissSplashScreen();
}
#Override
public void launchSplashScreen() {
super.onStart();
Drawable d = image.getDrawable();
if (d instanceof AnimatedVectorDrawable) {
Log.d("testanim", "onCreate: instancefound" + d.toString());
animation = (AnimatedVectorDrawable) d;
animation.start();
}
}
#Override
public void dismissSplashScreen() {
// Start Main Activity
startActivity(new Intent(SplashActivity.this,MainActivity.class));
finish();
}
}
AndroidManifest.java
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.simplesplashscreen">
<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/Theme.SimpleSplashScreen">
<activity
android:name=".SplashActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".MainActivity"
android:exported="true">
</activity>
<activity
android:name=".SecondActivity"
android:exported="true">
</activity>
</application>
</manifest>

Incorrect Activity when running App Android Studio

I have starting building an app in Android studio. I have established the MainPage as the launcher activity in the manifest.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/Theme.AppCompat.NoActionBar">
<activity android:name=".MainPage">
android:screenOrientation="portrait"
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".courseSelect" />
<activity android:name=".profile1" />
<activity android:name=".stats1" />
<activity android:name=".ReviewRounds" />
<activity android:name=".ReferFriends" />
<activity android:name=".RangeMode" />
</application>
I have double checked that the run configuration is set to 'Default' and yet the app is running a different activity, entitled courseSelect. It is also not running some code correctly on the NumberPicker. Even though I've set the picker to have a min, max, and default, the picker only shows 0 and will not scroll. The two issues seem to be related somehow, in terms of what activity is being run.
this is the courseSelectCode:
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.NumberPicker;
import co.ceryle.segmentedbutton.SegmentedButtonGroup;
public class courseSelect extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_course_select);
//Hole Picker
NumberPicker holePicker = (NumberPicker)findViewById(R.id.holePicker);
holePicker.setMaxValue(18);
holePicker.setMinValue(1);
holePicker.setWrapSelectorWheel(false);
holePicker.setValue(1);
SegmentedButtonGroup sbg = (SegmentedButtonGroup) findViewById(R.id.segmentedButtonGroup);
sbg.setOnClickedButtonPosition(new SegmentedButtonGroup.OnClickedButtonPosition() {
#Override
public void onClickedButtonPosition(int position) {
// if(position == 0)
}
});
}
}
I tried to set the run configuration specifically to the MainPage activity and it still opens in the courseSelect Page.
EDIT: on request, here is my MainPage.java code:
public class MainPage extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_course_select);
Window g = getWindow();
g.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION, WindowManager.LayoutParams.TYPE_STATUS_BAR);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
...
}
edit the Mainfest.xml, in order to enforce portrait layout there already:
<activity android:name=".MainPage"
android:screenOrientation="portrait"
android:configChanges="orientation|keyboardHidden">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
...which makes this code merely useless (styles.xml can also be used for window styles):
Window g = getWindow();
g.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION, WindowManager.LayoutParams.TYPE_STATUS_BAR);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
also update setContentView( R.layout.activity_course_select ); to the proper resource.
because it starts the MainPage Activity, but then inflates the wrong XML file.
one "suggested edit" before was to swap the order of setContentView() and the paragraph below ...which I've rejected, because setting it in Manifest.xml appeared more organized (less code).
First of all There is a mistake in your manifest file
you wrote screenOrientation attribute outside the opening tag
<activity android:name=".MainPage">
android:screenOrientation="portrait"
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
it should be
<activity
android:name=".MainPage"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
and you used wrong xml to setContenView
Try this and error was in 9th line because your code line is outside of the tag:
<activity android:name=".MainPage">
android:screenOrientation="portrait" // error
Do this :
<activity android:name=".MainPage"
android:screenOrientation="portrait"> // After doing this no error
and do also this thing :
public class MainPage extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_course_select); // error
do this :
public class MainPage extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.MAIN_PAGE_ACTIVITY_NAME); // no error
Your launcher activity is MainPage but you are calling the layout of courseselect activity inside MainPage activity's onCreate method on this line
setContentView(R.layout.activity_course_select);
Change it to your MainPage layout
setContentView(R.layout.yourMainPageLayout);

Android Applications Linking Activity

I have two different activities in my android applications. The first(MainActivity) has ImageButton through which onClick it's getting navigate two second activity(Numbers). This is my code of MainActivity
package com.android.learning_numbers;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.widget.ImageButton;
import android.view.View;
import android.view.View.OnClickListener;
public class MainActivity extends Activity {
ImageButton imageButton;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
addListenerOnButton();
}
public void addListenerOnButton() {
imageButton = (ImageButton) findViewById(R.id.button1);
imageButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
Intent intent = new Intent(MainActivity.this, Numbers.class);
startActivity(intent);
}
});
}
}
Now here there is no error in error log but when application is getting launched on click of imagebutton it is getting crashed. & showing error in LogCat. What i do now. Please help..
It would seem that you haven't declared the Numbers Activity in the Android Manifest.
If an Activity is not declared in the Manifest, as far as the application is concerned, the Activity does not exist which causes the application to crash.
<application>
<activity
android:name="com.android.learning_numbers.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.android.learning_numbers.Numbers"/>
</application>
Try this.. in your manifest before </application>
<activity
android:name="com.android.learning_numbers.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Numbers" />
<activity
android:name="com.android.learning_numbers.Numbers"
android:launchMode="singleTop"
android:screenOrientation="portrait"
android:theme="#android:style/Theme.NoTitleBar"
android:windowSoftInputMode="adjustResize" >

Activity B starts before Activity A

I was trying to get a small image to show up before my Main Activity starts. This is my current coding in the android manifest
<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=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.example.test.MAINACTIVITY" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
whatever I do, my splash screen does not start. They start separately, but never together, (I still haven't put a timer in my splash image as I want to check whether it works or not and it isn't working)
Remove
<intent-filter>
<action android:name="com.example.test.MAINACTIVITY" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
Use below code in splash screen after desired time
Intent intent=new Intent(this,MAINACTIVITY.class);
startActivity(intent);
finish(); //To close splashscreen when MAINACTIVITY loads
The above code starts with splash screen and after some time start your main activity
You should remove the <intent-filter> section from your MainActivity declaration ,
and launch the MainActivity from the splashActivity using a simple intent and startActivity call.
Try this.
<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=".MainActivity" >
</activity>
</application>
Code for your Splash Class-
package com.example.test;
import android.app.Activity;
import android.os.Bundle;
public class Splash extends Activity
{
#Override
protected void onCreate(Bundle savedInstanceState)
{ // TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
final Handler handle = new Handler();
Runnable delay = new Runnable() {
public void run() {
startActivity(new Intent(Splash.this, MainActivity.class));
finish();
}
};
handle.postDelayed(delay,5000);
}
}
its delay next intent 5 second. you can set time according to you.
Use This:
<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=".MainActivity" >
</activity>
</application>
and This :
public class Splash extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
public void run() {
Intent mInHome = new Intent(Splash.this, MainActivity.class);
Splash.this.startActivity(mInHome);
Splash.this.finish();
}
}, 3000);
}
}

won't run, won't switch activities

I want to create a splash screen that will then move to the login/register screen. My code looks like this:
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
public class AssaultTDActivity extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
this.TimeOut();
}
public void TimeOut(){
long start = System.currentTimeMillis();
boolean continueloop = true;
long timenow;
while (continueloop = true){
timenow = System.currentTimeMillis();
if (timenow - start > 5000){
continueloop = false;
this.GoToRegister();
}
}
}
public void GoToRegister(){
Intent i = new Intent(AssaultTDActivity.this, register_activity.class);
startActivity(i);
finish();
}
import android.app.Activity;
import android.os.Bundle;
import android.widget.Button;
import android.widget.TextView;
public class register_activity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.register);
}
}
and my manifest file is the following:
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity android:screenOrientation="landscape"
android:label="#string/app_name"
android:name=".AssaultTDActivity" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity class =".register_activity"
android:label="Log in"
android:screenOrientation="landscape"
android:name=".register_activity" >
</activity>
</application>
So am I doing something wrong here?
Also is there a command to "do events" while looping so you dot get stuck in a loop?
Hopefully this is the issue: looks like you may have had a find/replace mistake, this line in your manifest is wrong:
<uses-Activityk android:minActivitykVersion="8" />
Change it to:
<uses-sdk android:minSdkVersion="8" />
Because you added so many activities, it will most likely be fixed if you add:
<category android:name="android.intent.category.DEFAULT" />
So your main activity is the default activity and then the Android Launcher wont get tripped up.
<activity android:name=".MainActivity"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen"
android:screenOrientation="portrait"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
Taken from: http://developer.android.com/reference/android/content/Intent.html
Activities will very often need to support the CATEGORY_DEFAULT so
that they can be found by Context.startActivity()

Categories

Resources