Hello,
I test your demo, I find you create DoLongRunningOperationThings
method in DataSource.cs, but this method is empty. Please move your Accelerometer.ReadingChanged += Accelerometer_ReadingChanged;
code to DoLongRunningOperationThings
method and move related code from AboutPage.cs to DataSource.cs.
When I click the start button, make the application in background and lock the screen. When I get counter meet the If
condition, I get the Vibtate normally. My test device is
android 9.0 and android 1.0.
===========
Update=============
If you want to transfer data from DataSource.cs
to MainPage.xaml.cs
For example, I transfer result
data from Accelerometer_ReadingChanged
method of DataSource.cs
like following code.
void Accelerometer_ReadingChanged(object sender, AccelerometerChangedEventArgs e)
{
var data = e.Reading;
result = counter / 2;
//add transfer code here
MessagingCenter.Send<Object, string>(this, "TestMessage", result.ToString());
}
Then, you can get result in MainPage.xaml.cs , for testing, I set the text for Rakaat_1.Text
public MainPage()
{
InitializeComponent();
MessagingCenter.Subscribe<Object, string>(this, "TestMessage", (sender, arg) =>
{
string message = arg;
Rakaat_1.Text = message;
});
}
Best Regards,
Leon Lu
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.