android - can't change layout - android

I make a condition when the client receives the word "login success" then the first layout will be changed to the second layout.
The first layout is controlled by Client_layoutActivity class and
The second layout is controlled by chat_wall class class
I think this method is 100% correct because I've successfully tried before but when the conditions are met (received "login success"), the layout still does not change. I am looking for a solution on google but still not get the appropriate answers.
I use the method as shown below:
if (line.contentEquals("login success")){
Toast.makeText(this, "login success", Toast.LENGTH_SHORT).show();
Intent i = new Intent(Client_layoutActivity.this, chat_wall.class);
startActivity(i);
chat_wall cw = new chat_wall();
cw.send(out, in);
}

You need to read basics of android in more details, in this application if you need to switch between two activities:
then do the following:
Intent i = new Intent(Client_layoutActivity.this, chat_wall.class);
startActivity(i);
if you want to pass some data to other activity, use putExtra method of Intent, to do the same.

just check once the
setContentView(R.layout.chat_wall_layout);
is setted or not, in chat_wall activity.
also try
Intent i = new Intent(this.getApplicationContext(), chat_wall.class);

Related

My app doesn't open the correct activity - why so?

Good afternoon
I'm developing an Android App and i'm having some trouble with it.
I have many buttons it the app that are supposed to open activities. I don't want to have a lot of different onClick() methods so i'm trying to make one generic that can retrieve the correct activity to open depending on which button was clicked.
I came up with this code that works correctly:
public void displayActivity(View view) {
switch(view.getId()) {
case R.id.secondActitityButton:
myClass = SecondActivity.class;
break;
default:
throw new RuntimeException("Unknown Button");
}
Intent myIntent = new Intent (this, myClass);
startActivity (myIntent);
}
But this still means that i need to have a lot of switch cases (one for each button...). So i tried another aproach using the "Content Description" of the button to store the class name. This is the code:
public void displayActivity(View view) {
Class myClass;
String className = (view.getContentDescription().toString().trim());
try {
myClass = Class.forName(className);
}
catch (ClassNotFoundException e) {
myClass = MainActivity.class;
}
Intent myIntent = new Intent (this, myClass);
startActivity (myIntent);
}
The Content Description of the button was defined to "SecondActivity.class".
But now when i click the button it keeps sending me to the MainActivity.
I researched but just couldn't find the answer for this problem...
Can anybody help please?
Thanks in advance
Class#forName() expects a fully qualified name of the desired class. So class name should be something like the.complete.packagename.YourActivity.
Please note that's not the intended usage of content description, see Make apps more accessible. You should consider another approach.

Putting arguments to Activitiy.this in Android

how can I call MyActivitiy.this, but put arguments to it or to its Bundle?
My Code:
OnSwipeTouchListener onSwipeTouchListener = new OnSwipeTouchListener(MyActivitiy.this) {
#Override
public void onSwipeLeft() {
//your actions
}
};
The question doesn't seem to be very clear. But, consider declaring a Context ( set it equal to MyActivity.this) and using that as the parameter for your OnSwipeListener.
The way to communicate with an Activity is via Intents. In whatever code you use to start your Activity, go:
Intent intent = new Intent(someContext, MyActivity.class);
intent.putExtra("myKey", "whateverValue");
In your Activity's onCreate() method, use:
Intent intent = getIntent();
String message intent.getStringExtra("myKey", "aDefaultValueJustInCase");
Once that Activity is started, the String message will acquire the value "whateverValue".
As to using its Bundle, you probably only want to do that to recreate your Activity (say you're returning from another Activity, or pressed Back). Documentation for that is here.
Hope that answered your question. If not, please provide us more details and we will probably be able to provide more specific answers.

Android app seems hanging

I am trying to move from one activity to another activity. But some times seems it is hanging. On screen off and On it is working fine.
eg:
I am in Activity 1
Moved from Activity 1 to Activity 2
Seems it is hanged.
But if I do screen off and on it is on Activity 1.
Below is my Code sample:
Intent i;
i = new Intent(AdvSeatAvail.this, TrainsBetweenTwoStationsList.class);
i.putExtra("anim id in", R.anim.fragment_slide_right_enter);
i.putExtra("anim id out", R.anim.fragment_slide_left_exit);
i.putExtra("jsonvalue", jsonvalue);
i.putExtra("dateval", dateval);
AdvSeatAvail.this.finish();
AdvSeatAvail.this.startActivity(i);
overridePendingTransition(R.anim.fragment_slide_right_enter, R.anim.fragment_slide_left_exit);
Some one please help me to resolve this Issue.
--
thanks,
Kiran
Use below lines of code for it..
Firstly call another activity than finish the class
Intent i;
i = new Intent(AdvSeatAvail.this, TrainsBetweenTwoStationsList.class);
i.putExtra("anim id in", R.anim.fragment_slide_right_enter);
i.putExtra("anim id out", R.anim.fragment_slide_left_exit);
i.putExtra("jsonvalue", jsonvalue);
i.putExtra("dateval", dateval);
AdvSeatAvail.this.startActivity(i); //// FIRTLY START THE CLASS AND THAN FINISH THE CLASS
AdvSeatAvail.this.finish();
overridePendingTransition(R.anim.fragment_slide_right_enter, R.anim.fragment_slide_left_exit);
Try this:
finish();
Intent i = new Intent(AdvSeatAvail.this, TrainsBetweenTwoStationsList.class);
/* putExtra stuff */
startActivity(i);
Hopefuly it will help.

Running two activities at the same time on the screen

I need help doing something that I am sure is simple, but I can't figure out how to do it. I have a counter down and when it gets to the last 60 seconds, it calls a 'lastminute' counter activity. The plan is to overlap the last 60 seconds over the actual application.
Here is the problem, how can I change the code to allow the two activities to start at the same time.
I have tried this;
public void onFinish() {
startActivity(new Intent ("eu.merso.phoneapp.LASTMINUTE"));
startActivity(new Intent ("eu.merso.phoneapp.DASHBOARD"));
onDestroy();
}
but this does not put both applications on the screen, what I want is DASHBOARD on the background and LASTMINUTE on top. LASTMINUTE is alreay a "transparency colour".
Thanks;
Ramón
It won't work the way you're currently trying to do it. There can only be one visible activity at a time.
You should first start the dashboard Activity and from there you should start lastminute.
Edit --
Use a Bundle object.
Bundle bundle = new Bundle();
// Use 0 when the activity is called by the button and
// 1 when it is called by the timer.
bundle.putInt("event_src", 0);
intentObject.putExtras(bundle);
// In your new activity you can then check whether to display
// the countdown or not
Int eventSrc = getIntent().getExtras().getInt("event_src")
You need to implement the lastminute functionality in a dialog that you create and show in the onCreate method of your dashboard activity.
EDIT:
To distinguish between which activity that starts the new activity, use intent extras:
//in your calling activity
Intent i = new Intent(A.this, B.class);
i.putExtra("from Activity", A.class.getSimpleName());
startActivity(i);
//in your receiving activity
String from = getIntent().getStringExtra();
if(from.equals(A.class.getSimpleName())){
//do something
}
else if(from.equals(C.class.getSimpleName())){
//do something
}
Try using android:theme="#android:style/Theme.Translucent.NoTitleBar in Activity attributes for LastMinute in AndroidManifest.xml. I hope it'll be productive.
I think using Android fragments will help u to show two separate activities in the context of another main activity.
try reading this:
http://developer.android.com/guide/components/fragments.html

Changing Screen / New Intent

I am trying to change screens from the first to second and back again, but with some extra variables passed. At the moment I go from 1 to 2, but when I click from 2 back to 1 it causes an error that the application stopped unexpectantly. I have issolated the problem to this part of the code. I'm not at the moment trying to pass any other variables with it just get it to change.
1st page package = max.multiplebuttons.com
Activity = multibuttons
1st page package = max.reason.com
Activity = reason_screen
public void nextquestion(){
Intent a = new Intent();
a.setClassName("max.reason.com", "max.multiplebuttons.com.multibuttons");
startActivity(a);
}
a.setClassName("max.reason.com", "max.multiplebuttons.com.multibuttons");
Your problem is here. The class multibuttons isn't inside the package max.reason.com.
Edit:
I can't give you the exact syntax because I need to see the naming conventions, but you have to do something like this:
Intent a = new Intent(Activity1.this, Activity2.class);
startActivity(a);

Categories

Resources