first question here by a Kotlin and AndroidStudio noob.
I made an app and want to go from one activity to another. I use buttons to navigate from the MainScreen to the 2 different screens. In Main I have this:
val firstBTN: Button = findViewById (R.id.firstBTN)
firstBTN.setOnClickListener {
val intent = Intent(this, FirstActivity::class.java)
intent.putExtra("Collection", collection as Serializable)
intent.putExtra("Result", result)
startActivity(intent)
collection is a MutableListOf objects called Edibles (String, Double) that I want to give to the next activity
it is then received by this:
val intentE = getIntent()
var collection = intent.getSerializableExtra("Collection") as MutableList<Edibles>
var result = intent.getDoubleExtra("Result",0.0)
But everytime I press firstBTN the App stops working.Unfortunately I don't even get any bug report, so I have no idea what's the problem. I thought it might be the "as MutableList" part, but I even created an element before passing to the next activity and the same happened...
Thank you already for your help!
This could be anything. You should provide more data.
For starters your Android Manifest. Did you put your second activity in there?
Does the call work without the putExtra?
Second, what type is collection? Is the source data class annotated with #Serializable? I am not very sure that as Serializable alone will work because there are different Serializables.
https://kotlinlang.org/docs/serialization.html#example-json-serialization
When LogCat does not work, check about filters. If there are none and you see any reactions, then restart Android Studio. There are some Bugs which can stop LogCat from working.
Related
Observablecollection is bound to gridview in UWP project. If I try to clear and add data it fails with an error because it can only be modified on the UI thread.
I have set up service broker with SQL to notify the app when there is a change to the data. This is working correctly. However, every time I try to clear and modify the observablecollection I get an exception thrown.
using (SqlDataReader dr = cmd.ExecuteReader())
{
while (dr.Read())
{
EmployeeLists.Add(new Employee { Name = dr[0].ToString(), Loc = dr[2].ToString() });
}
}
This is the code I'm using at first to populate the observable collection. I want to listen for changes which is working. But how do I update the changes and sync them to the observable collection?
I have tried clearing the employeelists observablecollection and then adding everything again. It seems clunky, but doesn't work anyway because It says I cannot modify from another thread. I have tried several solutions online, but I'm not that familiar with ASYNC programming. Can anyone point me in the right direction?!
Android :
What I've implemented till now is, get spinner value to the immediate subscriber using itemSelection().
Code :
Observavle observavle = RxAdapterView.itemSelections(spinner);
observable.subscribeOn(AndroidSchedulers.mainThread())
.subscribe(integer -> {
Log.v("spinner", integer.toString());
});
What I want to achieve is :
I want to subscribe multiple observers to this Observable.
For which I have created few Observers and used
Observable.subscribe(observer1);
Observable.subscribe(observer2);
Observable.subscribe(few more observers);
To get spinner updated value on these observers, but this is not working,
OnNext() of these observers won't get called on spinner value change.
(Note: This situation works perfectly in case of RxBinding Textview using on textchange() ).
Will surely upvote if you can help me with this.
You can use the share() operator:
Observavle observavle = RxAdapterView.itemSelections(spinner).share();
You can read more about share() in this blog post.
firstly let my say that the mdc documentation is difficult for non-pros like me.
I'm using Elixir Phoenix and Brunch.
I import and everything is fine.
import {MDCTab, MDCTabFoundation} from '#material/tabs'; import
{MDCTabBar, MDCTabBarFoundation} from '#material/tabs'; import
{MDCTabBarScroller, MDCTabBarScrollerFoundation} from
'#material/tabs';
I manually instantiate the tab bar in a separate function that I export
export var Tabbable = {
run: function(MDCTabBar, el){
var myDynamicTabBar = window.myDynamicTabBar = new MDCTabBar(document.querySelector('#' + el));
Which is following the documentation like this
const tabBar = new MDCTabBar(document.querySelector('#my-mdc-tab-bar'));
but is slightly different to the documentation's use of the tab bar in their code snippet
var dynamicTabBar = window.dynamicTabBar = new mdc.tabs.MDCTabBar(document.querySelector('#dynamic-tab-bar'));
But, whenever I try to use mdc I get a 'not defined' error. Therefore, I'm not using it :-)
Now, when the user clicks the tab bar I capture that like this:
myDynamicTabBar.listen('MDCTabBar:change', function ({detail: tabs}) {
var nthChildIndex = tabs.activeTabIndex;
updatePanel(nthChildIndex);
});
The subtle difference is that my myDynamicTabBar is MDCTabBar but the documentation's dynamicTabBar is mdc.tabs.MDCTabBar
My tab control works, but it throws an error only visible in the console:
Uncaught Error: Invalid tab component given as activeTab: Tab not
found within this component's tab list
which is likely because I'm not using mdc.tabs? The documentation notes the change event happens on the MDCTabBar.
Therefore, how do I get rid of this annoying error in the console?
And why can I not access the global mdc? I have tried this in my Brunch file
globals: { mdc: "#material"}
But no good.
I'm right behind you on this! I'm frustrated with the docs too :(
You answered your own question in this Elixir thread which is very informative.
I found the real solution in this thread https://github.com/hyperapp/hyperapp/issues/546
MDCTabBar automatically initiates its children. So initiating tabs will result in that error.
The fix is to just initiate MDCTabBar
In a new Xna game I wroted this:
GamerServicesComponent gsc = new GamerServicesComponent(this);
gsc.Initialize();
Components.Add(gsc);
if(!GamerServicesDispatcher.IsInitialized)
GamerServicesDispatcher.Initialize(Services);
And in the Update method
if (Keyboard.GetState().IsKeyDown(Keys.S))
if (!Guide.IsVisible)
Guide.ShowSignIn(1, false); // true doesn't solve it nor 2 or 4 as paneCount
I'm receiving a
Value does not fall within the expected range.
Anybody?
It seems that Guide.ShowSignIn() can't be used anymore. I Don't know the reason nor if it is really true. But I couldn't get it working with ShowSignIn.
The way I had to login was by pressing the Home button.
The Guide will appear and you can simply follow the Guide to login.
Waiting a few frames before calling Guide.ShowSignIn() works for me. I don't call it until my game has loaded all assets and at least I frame has been rendered.
I'm new to android. Actually one handler is running in Home Activity A for every 30 sec to check the net connection.
If I'm went to activity C by A->B->C, If there in no net connection at that time, then i want to close Activity B and C, then want to show message box in Activity A.
But My problem is My handler is running for every 30 sec in Home Activity A. But If i was in Activity C or some other Activity how to find which activity is my Application currently focussed now. Then i want to finish those child activities and want to show Home Activity A I have some 9 child activities in Activity B.
I heard about using "FLAG_ACTIVITY_CLEAR_TOP" . I used the code as follows in the handler in Home activity A itself. But got error.
Intent intent = new Intent( ctx, Homepage.class );
intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP |
Intent.FLAG_ACTIVITY_CLEAR_TOP);
ctx.startActivity( intent );
Here Homepage.class is my Home Activity A and i set that activity in manifest file as
android:launchMode="singleTop"
Please help!
You can start Activity A and close all other activities.
You have to create new intent and add flag FLAG_ACTIVITY_CLEAR_TOP
Intent activityA = new Intent(context, ActivityA.class);
activityA.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
context.StartActivity(activityA);
this will close all activities that are in the stack and are at the top of activity A
When calling Acitivity C, call finish in activity B , when calling Activity A from C , call finish() in activity C !
You can use, According to me two ways,
If you start an activity using startActivityForResult, then you can call finish() in this new Activity when you're done with it and it will return control to the activity that started it.
OR otherwise, May be I am wrong,
Call finish inside onStop 'override method'.
make a uniform resultCode for closing child activities. Eg. you make 911 (should be int) as your resultCode. If you want your Activity to finish and go back directly to parent Activity, you set the resultCode to 911:
setResult(911); finish();
In every child activity, you override the onActivityResult and check if the resultCode is 911. If yes, then call the setResult(911); finish(); until you get back to your parent activity. Hope this helps!
For example, if you want to start intentB, you can do following in old activity:
Intent intentB = new Intent();
intentB.setClass(XYZ.this, abc.class);
intentB.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intentB);