In my %MainActivity I have this
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Intent intent = new Intent(MainActivity.this,
LoginSignupActivity.class);
startActivity(intent);
....
}
In fact, the intent is wrapped by a some authentication check but to debug I deleted it, but this method doesn't launch any LoginSignupActivity. Could someone help ?
Edit:
Here's the entire onCreate method
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Intent intent = new Intent(MainActivity.this,
LoginSignupActivity.class);
startActivity(intent);
setActionBarListNavigation();
setupDrawer();
setupContainer();
}
MainActivity extends CustomActivity (which lods data from AsyncLoader) and this last Activity inherits from FragmentActivity and has an onCreate method
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
theme = getAppTheme();
setupActionBar();
}
with
protected void setupActionBar()
{
getActionBar().setDisplayHomeAsUpEnabled(true);
getActionBar().setHomeButtonEnabled(true);
getActionBar().setBackgroundDrawable(getResources().getDrawable(theme));
}
At last
add: startActivity(intent);
Intent intent = new Intent(this, LoginSignupActivity.class);
startActivity(intent);
and add LoginSignupActivity into your Manifest.xml
<activity
android:name=".LoginSignupActivity"
android:label="Login" >
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Intent intent = new Intent(MainActivity.this,
LoginSignupActivity.class);
startActivity(intent);
}
register your all activity in manifest.xml
<activity android:name=".LoginSignupActivity"/>
Just had this problem, I needed to add my custom jar library to the build.gradle file:
dependencies {
compile files('libs/android-support-v4.jar')
ADD FILE HERE
}
/**
* A {#code TaskSelectionException} is thrown when the tasks to execute cannot be selected due to some user input
* problem.
*/
public class TaskSelectionException extends InvalidUserDataException {
public TaskSelectionException(String message) {
super(message);
}
}
You are launching an Activity during "onCreate" - you will not see your main activity (it never reaches "onStart" or "onResume").
So, if you are having problems, it is not in your MainActivity, it is in the other one, LoginSignupActivity.
Related
I'm trying to start another activity by pressing on the cardview which has a friend finder id. But when I write home.java it gives me problems in the setOnClickListener. At homeActivity it tells me Cannot resolve method 'homeActivity' in 'HomeActivity'. because?
public class HomeActivity extends AppCompatActivity {
private CardView btn_home;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn_home = findViewById(androidx.appcompat.R.id.home);
btn_home.setOnClickListener(v -> homeActivity(new Intent(HomeActivity.this, TrovamicoActivity.class)));
}
btn_home.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent intent = new Intent(HomeActivity.this, TrovamicoActivity.class);
startActivity(intent);
}
});
If there is no code in the manifest, write it
<activity android:name=".TrovamicoActivity" />
i try to make an intent which is used to go to a 2nd activity. however when i try to click on it, it makes my application crash.
here's the code:
public class MainActivity extends AppCompatActivity {
private Button mButtonCommande;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mButtonCommande=findViewById(R.id.buttonAccessCommande);
mButtonCommande.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
openCommandeActivity();
}
});
}
public void openCommandeActivity() {//cette méthode me sert à envoyer vers l'activité commande
Intent intent = new Intent(this, CommandeActivity.class );
startActivity(intent);
}
idk where it keeps crashing and i need help.
Make sure you declared the target activity in AndroidManifest.xml.
In your AndroidManifest.xml, add the following inside the <application> element:
<activity android:name=".CommandeActivity"/>
How can I refresh or update activity when it is starting?
I have code ThemeSwitcher in SecondActivity, when I switch theme and return to MainActivity, theme is't changes, only when I restart an app
You should open your MainActivity then finish your second activity
Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);
finish();
Then you should set your theme before super.onCreate(savedInstanceState);
#Override
protected void onCreate(Bundle savedInstanceState) {
setYourTheme();
super.onCreate(savedInstanceState);
}
I created a project that use RecyclerView and CardView (for PointOfInterest). These 5 activities are relate to each other :
PointOfInterest.java
PlacesAdapter.java
Places.java
layout_poi.xml
activity_point_of_interest.xml
Meanwhile in activity_main.xml I design the Main Menu together with some buttons. One of the button named Rapid Penang (id: rapid_btn). I call an activity of Rapid Penang (from MainActivity.java) like below:
public class MainActivity extends AppCompatActivity {
private Button button_for_rapid;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// to call Rapid Penang class
button_for_rapid = (Button) findViewById(R.id.rapid_btn);
button_for_rapid.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
openRapid();
}
});
}
public void openRapid()
{
Intent intent_rapid = new Intent(this, RapidPenang.class);
startActivity(intent_rapid);
}
}
RapidPenang consist of only one activity and it is success. But when I try to do exactly the same to PointOfInterest activites (as mention above), suddenly the app were crashed.
This is how I try to open PointOfInterest activites from a button in MainMenu called Point Of Interest:
private Button button_for_poi;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// to call Point Of Interest class
button_for_poi = (Button) findViewById(R.id.poi_btn);
button_for_poi.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
openPOI();
}
});
}
public void openPOI()
{
Intent intent_poi = new Intent(this, PointOfInterest.class);
Intent intent_poi2 = new Intent(this, PlacesAdapter.class);
Intent intent_poi3 = new Intent(this, Places.class);
startActivity(intent_poi);
}
Firstly check your activity is define in Android manifest file and then call
StartActivity(new Intent(getApplicationcontext(),RapidPenang.class));
That's it
Below are two Activities:
Test_Result.java
Intent intent = new Intent();
intent.putExtra("flag","data");
intent.setClass(Test_Result.this, MainActivity.class);
startActivity(intent);
MainActivity.java
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);
mainPager=(MyViewPager) findViewById(R.id.vPager);
radioGroup=(RadioGroup) findViewById(R.id.bottom_bar);
radioGroup.setOnCheckedChangeListener(this);
Intent intent = getIntent();
flag = intent.getStringExtra("flag");
if (flag == null){
initViews();
radioGroup.getChildAt(2).performClick();
}
else {
if (flag.equals("test")) {
initViews();
radioGroup.getChildAt(0).performClick();
}
if (flag.equals("data")) {
initViews();
radioGroup.getChildAt(1).performClick();
}
if (flag.equals("info")) {
initViews();
radioGroup.getChildAt(2).performClick();
}
}
}
private void initViews(){
fm=getSupportFragmentManager();
fragments=new ArrayList<Fragment>();
testFragment=TestFragment.getInstance();
dataFragment= DataFragment.getInstance();
informationFragment=InformationFragment.getInstance();
fragments.add(testFragment);
fragments.add(dataFragment);
fragments.add(informationFragment);
mainPager.setAdapter(new MainPageAdpter(fm));
}
When it jumps,there is no view in 3 fragments except radioGroup.
But when I open the app, three fragments are there in MainActivity.
Why? I just began to learn Android two weeks ago and I am innocent, please help me.