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);
Related
I create a personnal component view and when we click on this, an other activity starts. There is my manifest.
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="fr.freshkamekentrainement.skrt">
<application
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme">
<activity android:name=".Splash"
android:theme="#style/Splash"
android:screenOrientation="portrait"
android:configChanges="orientation">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".MainActivity"
android:screenOrientation="portrait"
android:configChanges="orientation"/>
<activity android:name=".niveaux.LilUziVert_GrowUp"
android:screenOrientation="portrait"
android:configChanges="orientation"/>
</application></manifest>
there is my intent
public class Niveauview extends RelativeLayout {
Intent intentNiveau;
//Code
#Override
public void onFinishInflate() {
super.onFinishInflate();
setOnClickListener(new OnClickListener() {
#Override
public void onClick(View view) {
intentNiveau = new Intent(MainActivity.this,LilUziVert_GrowUp.class);
startActivity(intentNiveau);
}
});
}}
I get error:
MainActity is not an enclosing class
Notice that NiveauView and MainActivity isn't in the same package (but they are public). Where does the problem come from? When i try new Intent(this,LilUziVert_GrowUp.class); i have an error too.
You can only access Foo.this if you're in a inner class of Foo. Otherwise you need to be passed in an instance of Foo instead. In the case of a View, every view has an instance of a Context you can get by calling getContext(). So you need to call intentNiveau = new Intent(getContext(),LilUziVert_GrowUp.class);
I am Running the application from eclipse and it's being launched twice: first time launching the app, then again relaunching after few seconds
My app Splash Screen--->> Main activity(Both Opening twice).
i already tried adding android:launchMode="singleInstance" in my manifest file, but not success.
i have tried 3 different applications from my eclipse still opening twice in my Kitkat ,lollipop real device (created new project that one also opening twice)
EDIT 1 :
Tried adding this line in manifest file but not Success-android:launchMode="singleTop"
please let me know How to solve this issue.
manifest file:
<application
android:allowBackup="true"
android:icon="#drawable/logo"
android:label="#string/app_name"
android:largeHeap="true"
android:launchMode="singleInstance"
android:theme="#style/AppTheme2" >
<activity
android:name=".Start"
android:label="#string/app_name"
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=".MainActivity"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
My start Activity.java
public class Start extends Activity
{
SessionManagerFor_Signin session;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Session class instance
session = new SessionManagerFor_Signin(getApplicationContext());
// Remove the Title Bar
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.start);
ImageView Image1=(ImageView)findViewById(R.id.imageView1);
//Animation Bottom to Top
TranslateAnimation animation2 = new TranslateAnimation(0.0f, 0.0f,400.0f, 0.0f);
animation2.setDuration(1000);
animation2.setFillAfter(false);
Image1.startAnimation(animation2);
Thread timer = new Thread()
{
#Override
public void run()
{
try {
sleep(3000);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
finally
{
session.checkLogin();
finish();
}
}
};
timer.start();
//For Full Action bar Color Starts
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
setTranslucentStatus(true);
}
SystemBarTintManager tintManager = new SystemBarTintManager(this);
tintManager.setStatusBarTintEnabled(true);
tintManager.setStatusBarTintResource(R.color.FUllStartColor);
//For Full Action bar Color Ends here
}
#TargetApi(19)
private void setTranslucentStatus(boolean on) {
Window win = getWindow();
WindowManager.LayoutParams winParams = win.getAttributes();
final int bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS;
if (on) {
winParams.flags |= bits;
} else {
winParams.flags &= ~bits;
}
win.setAttributes(winParams);
}
Try adding launchMode "singleTop" in your Manifest to your activity.
<activity
android:name="MyActivity"
android:launchMode="singleTop"
... >
Apply intent filter only in one of your activity. Remove from MainActivity...
<application
android:allowBackup="true"
android:icon="#drawable/logo"
android:label="#string/app_name"
android:largeHeap="true"
android:launchMode="singleInstance"
android:theme="#style/AppTheme2" >
<activity
android:name=".Start"
android:label="#string/app_name"
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=".MainActivity"
android:screenOrientation="portrait" >
</activity>
</application>
Remove this from one of the two activities:
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
This intent-filter indicates to Android which is the Main Activity, and you should have one only.
try this:
android:launchMode="singleTask"
May be this will work.
If it does not work then reinstall eclipse.
Apply the below to your splash screen activity,then clean the project and run again..
Try to register activity in manifest file with complete package name.
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
I'm trying to create splash screen without action bar.
Firstly before created splash screen, action bar in main activity and when I create splash screen, action bar comes to splash screen and main activity is full screen. I searched method like getwindow(), getActionBar(), but when I use these method program says to me unfortunately stopped. So what I'm missing?
How can I avoid actionBar in splash screen?
My code:
public class MainActivity extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash_item);
Thread th=new Thread(){
public void run(){
try {
sleep(4000);
Intent intent=new Intent(MainActivity.this,SplashScreen.class);
startActivity(intent);
} catch (Exception e) {
e.printStackTrace();
}
finally{
finish();
}
}
};
th.start();
}
MANÄ°FEST:
<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>
<activity
android:name=".SplashScreen"
android:label="#string/app_name"
>
<intent-filter>
<action android:name="android.intent.action.SPLASHSCREEN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
First, import the support library in the top of your app:
import android.support.v7.app.ActionBarActivity;
and change your code as follows:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash_item);
getSupportActionBar().hide();
}
Using AppCompat for being supported for all versions:
<activity
android:theme="#style/Theme.AppCompat.Light.NoActionBar">
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
Put that before your setContentView(...), should get the job done.
For Android 3.0 or higher use ActionBarAPI#hide
For lower versions you will need to use Android Support Library.
Use ActionBar as
ActionBar actionBar = getSupportActionBar();
actionBar.hide();
Ref docs
Also if your requirement in static, then you can choose a theme for your activity that dos not have actionbar such as
android:theme="#android:style/Theme.Holo.Light.NoActionBar"
You can do this as:
<activity android:theme="#android:style/Theme.Holo.Light.NoActionBar"
android:name=".name_here"
android:label="#string/app_name" >
use a style without actionbar, also in your splash screen activity java extend Activity and make the splash screen your MAIN activity and in this activity you call an Intent to open your MainActivity after some seconds
<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" >
</activity>
<activity android:theme="#android:style/Theme.Holo.Light.NoActionBar"
android:name=".SplashScreen"
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>
Example:
In your SplashScreen activity write this code. This will open your MainActivity after 2 seconds.
new Handler().postDelayed(new Runnable()
{
public void run()
{
Intent localIntent = new Intent(SplashScreen.this, MainActivity.class);
SplashScreen.this.startActivity(localIntent);
SplashScreen.this.finish();
}
}, 2000L);
This is the simplest method.
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_main);
}
where R.layout.activity_main is replaced by your layout activity e.g. activity_splash
Im very new to android development so please bear my ignorance.
I created a Splash screen before loading my main activity. Splash is working fine but what causes the problem is the main activity, it keeps on instantiating.
Splash.java
public class Splash extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
final AdController optinController = new AdController(
getApplicationContext(), "SECTION_ID");
final Splash splash = this;
optinController.loadOptin((Activity) splash, "SECTION_ID",
new AdOptinListener() {
public void onAdOptin() {
// once optin process is complete, continue to main app activity
launchMain();
}
}
);
}
public void launchMain() {
finish();
Intent myIntent = new Intent(Splash.this, MainActivity.class);
myIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);
startActivity(myIntent);
}
}
MainActivity.java
public class MainActivity extends Activity {
private AdController myController;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
myController = new AdController(getApplicationContext(), "SECTION_ID");
myController.loadNotification();
}
}
In the manifest file:
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".Splash"
android:label="#string/title_activity_splash" >
<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/title_activity_main"
android:launchMode="singleInstance">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
I used android:launchMode="singleInstance" but still it keeps on reinstantiating.
Please help. Thanks in advance.
public class Splash extends Activity{
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);//|Window.FEATURE_INDETERMINATE_PROGRESS
setContentView(R.layout.splash);
final Timer time = new Timer();
time.schedule(new TimerTask() {
#Override
public void run() {
Intent intent = new Intent(Splash.this,MainActivity.class);
startActivity(intent);
finish();
}
},1000);
}}
It will work , i din get you exactly by instatiating.Also do no use single instance,you are not supposed to require it here.
Yes, following is my snippet of manifest file , just use a timer for your splash screen and move to your main class after specific time.
activity android:name=".Splash"
android:screenOrientation="portrait" android:label="#string/app_name">
i think you have to remove the intent flag Intent.FLAG_ACTIVITY_SINGLE_TOP
In manifest.xml, set category as LAUNCHER which activity you want to launch first and to Other set as DEFAULT as given in below example.
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".Splash"
android:label="#string/title_activity_splash" >
<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/title_activity_main"
android:launchMode="singleInstance">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
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()