Skip to content

Commit

Permalink
Start and Final solutions for ActivityLifecycle topic.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark McLemore committed Sep 4, 2015
1 parent 5ca8ad6 commit 41f13b5
Show file tree
Hide file tree
Showing 24 changed files with 362 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@
<ProjectGuid>{B4994EC0-5A8F-4D29-BF89-BE5C9E657438}</ProjectGuid>
<ProjectTypeGuids>{EFBA0AD7-5A72-4C68-AF49-83D382785DCF};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<OutputType>Library</OutputType>
<RootNamespace>ActivityLifecyle</RootNamespace>
<RootNamespace>ActivityLifecycle</RootNamespace>
<MonoAndroidResourcePrefix>Resources</MonoAndroidResourcePrefix>
<MonoAndroidAssetsPrefix>Assets</MonoAndroidAssetsPrefix>
<AndroidResgenClass>Resource</AndroidResgenClass>
<AndroidApplication>True</AndroidApplication>
<AndroidResgenFile>Resources\Resource.designer.cs</AndroidResgenFile>
<AssemblyName>ActivityLifecyle</AssemblyName>
<AssemblyName>ActivityLifecycle</AssemblyName>
<AndroidManifest>Properties\AndroidManifest.xml</AndroidManifest>
<AndroidUseLatestPlatformSdk>False</AndroidUseLatestPlatformSdk>
<TargetFrameworkVersion>v4.4</TargetFrameworkVersion>
<TargetFrameworkVersion>v5.0</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>True</DebugSymbols>
Expand Down Expand Up @@ -62,7 +62,7 @@
<AndroidResource Include="Resources\drawable\Icon.png" />
</ItemGroup>
<ItemGroup>
<None Include="Properties\AndroidManifest.xml" />
<Content Include="Properties\AndroidManifest.xml" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Novell\Novell.MonoDroid.CSharp.targets" />
</Project>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.21005.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ActivityLifecyle", "ActivityLifecyle.csproj", "{B4994EC0-5A8F-4D29-BF89-BE5C9E657438}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ActivityLifecycle", "ActivityLifecycle.csproj", "{B4994EC0-5A8F-4D29-BF89-BE5C9E657438}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -21,6 +21,6 @@ Global
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(MonoDevelopProperties) = preSolution
StartupItem = ActivityLifecyle.csproj
StartupItem = ActivityLifecycle.csproj
EndGlobalSection
EndGlobal
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace ActivityLifecyle
namespace ActivityLifecycle
{
using Android.App;
using Android.Content;
Expand All @@ -9,39 +9,40 @@ namespace ActivityLifecyle
[Activity(Label = "Activity A", MainLauncher = true)]
public class MainActivity : Activity
{
int _counter = 0;
int _counter = 0;

protected override void OnCreate(Bundle bundle)
{
Log.Debug(GetType().FullName, "Activity A - OnCreate");
base.OnCreate(bundle);
SetContentView (Resource.Layout.Main);
FindViewById<Button>(Resource.Id.myButton).Click += (sender, args) =>
{
var intent = new Intent(this, typeof(SecondActivity));
StartActivity(intent);
};
if (bundle != null)
{
_counter = bundle.GetInt ("click_count", 0);
Log.Debug(GetType().FullName, "Recovered instance state");
}

var clickbutton = FindViewById<Button> (Resource.Id.clickButton);
clickbutton.Text = Resources.GetString (Resource.String.counterbutton_text, _counter);
clickbutton.Click += (object sender, System.EventArgs e) =>
{
_counter++;
clickbutton.Text = Resources.GetString (Resource.String.counterbutton_text, _counter);
} ;
{
var intent = new Intent(this, typeof(SecondActivity));
StartActivity(intent);
};
if (bundle != null)
{
_counter = bundle.GetInt("click_count", 0);
Log.Debug(GetType().FullName, "Activity A - Recovered instance state");
}
var clickbutton = FindViewById<Button>(Resource.Id.clickButton);
clickbutton.Text = Resources.GetString(Resource.String.counterbutton_text, _counter);
clickbutton.Click += (object sender, System.EventArgs e) =>
{
_counter++;
clickbutton.Text = Resources.GetString(Resource.String.counterbutton_text, _counter);
};
}

protected override void OnSaveInstanceState (Bundle outState)
{
outState.PutInt ("click_count", _counter);
Log.Debug(GetType().FullName, "Saving instance state");
base.OnSaveInstanceState (outState); // always call the base implementation!
}
protected override void OnSaveInstanceState (Bundle outState)
{
outState.PutInt ("click_count", _counter);
Log.Debug(GetType().FullName, "Activity A - Saving instance state");

// always call the base implementation!
base.OnSaveInstanceState (outState);
}

protected override void OnDestroy()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="ActivityLifecycle.ActivityLifecycle" android:versionCode="1" android:versionName="1.0">
<uses-sdk android:minSdkVersion="19" />
<application android:label="ActivityLifecycle" android:icon="@drawable/Icon"></application>
</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// Information about this assembly is defined by the following attributes.
// Change them to the values specific to your project.

[assembly: AssemblyTitle("ActivityLifecyle")]
[assembly: AssemblyTitle("ActivityLifecycle")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
<resources>
<string name="mybutton_text">Start Activity B</string>
<string name="counterbutton_text">I\'ve been touched %1$d times.</string>
<string name="app_name">ActivityLifecyle</string>
<string name="app_name">ActivityLifecycle</string>
</resources>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace ActivityLifecyle
namespace ActivityLifecycle
{
using Android.App;
using Android.OS;
Expand Down
68 changes: 68 additions & 0 deletions ActivityLifecycle/ActivityLifecycle_Start/ActivityLifecycle.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>10.0.0</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{B4994EC0-5A8F-4D29-BF89-BE5C9E657438}</ProjectGuid>
<ProjectTypeGuids>{EFBA0AD7-5A72-4C68-AF49-83D382785DCF};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<OutputType>Library</OutputType>
<RootNamespace>ActivityLifecycle</RootNamespace>
<MonoAndroidResourcePrefix>Resources</MonoAndroidResourcePrefix>
<MonoAndroidAssetsPrefix>Assets</MonoAndroidAssetsPrefix>
<AndroidResgenClass>Resource</AndroidResgenClass>
<AndroidApplication>True</AndroidApplication>
<AndroidResgenFile>Resources\Resource.designer.cs</AndroidResgenFile>
<AssemblyName>ActivityLifecycle</AssemblyName>
<AndroidManifest>Properties\AndroidManifest.xml</AndroidManifest>
<AndroidUseLatestPlatformSdk>False</AndroidUseLatestPlatformSdk>
<TargetFrameworkVersion>v5.0</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>True</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>False</Optimize>
<OutputPath>bin\Debug</OutputPath>
<DefineConstants>DEBUG;</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>False</ConsolePause>
<AndroidLinkMode>None</AndroidLinkMode>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>none</DebugType>
<Optimize>True</Optimize>
<OutputPath>bin\Release</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>False</ConsolePause>
<AndroidUseSharedRuntime>False</AndroidUseSharedRuntime>
<AndroidLinkMode>SdkOnly</AndroidLinkMode>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Xml" />
<Reference Include="System.Core" />
<Reference Include="Mono.Android" />
</ItemGroup>
<ItemGroup>
<Compile Include="MainActivity.cs" />
<Compile Include="Resources\Resource.designer.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SecondActivity.cs" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\AboutResources.txt" />
<None Include="Assets\AboutAssets.txt" />
</ItemGroup>
<ItemGroup>
<AndroidResource Include="Resources\layout\Main.axml" />
<AndroidResource Include="Resources\values\Strings.xml" />
<AndroidResource Include="Resources\drawable\Icon.png" />
</ItemGroup>
<ItemGroup>
<Content Include="Properties\AndroidManifest.xml" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Novell\Novell.MonoDroid.CSharp.targets" />
</Project>
26 changes: 26 additions & 0 deletions ActivityLifecycle/ActivityLifecycle_Start/ActivityLifecycle.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.21005.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ActivityLifecycle", "ActivityLifecycle.csproj", "{B4994EC0-5A8F-4D29-BF89-BE5C9E657438}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{B4994EC0-5A8F-4D29-BF89-BE5C9E657438}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B4994EC0-5A8F-4D29-BF89-BE5C9E657438}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B4994EC0-5A8F-4D29-BF89-BE5C9E657438}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
{B4994EC0-5A8F-4D29-BF89-BE5C9E657438}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B4994EC0-5A8F-4D29-BF89-BE5C9E657438}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(MonoDevelopProperties) = preSolution
StartupItem = ActivityLifecycle.csproj
EndGlobalSection
EndGlobal
19 changes: 19 additions & 0 deletions ActivityLifecycle/ActivityLifecycle_Start/Assets/AboutAssets.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Any raw assets you want to be deployed with your application can be placed in
this directory (and child directories) and given a Build Action of "AndroidAsset".

These files will be deployed with you package and will be accessible using Android's
AssetManager, like this:

public class ReadAsset : Activity
{
protected override void OnCreate (Bundle bundle)
{
base.OnCreate (bundle);

InputStream input = Assets.Open ("my_asset.txt");
}
}

Additionally, some Android functions will automatically load asset files:

Typeface tf = Typeface.CreateFromAsset (Context.Assets, "fonts/samplefont.ttf");
60 changes: 60 additions & 0 deletions ActivityLifecycle/ActivityLifecycle_Start/MainActivity.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
namespace ActivityLifecycle
{
using Android.App;
using Android.Content;
using Android.OS;
using Android.Util;
using Android.Widget;

[Activity(Label = "Activity A", MainLauncher = true)]
public class MainActivity : Activity
{
protected override void OnCreate(Bundle bundle)
{
Log.Debug(GetType().FullName, "Activity A - OnCreate");
base.OnCreate(bundle);
SetContentView (Resource.Layout.Main);
FindViewById<Button>(Resource.Id.myButton).Click += (sender, args) =>
{
var intent = new Intent(this, typeof(SecondActivity));
StartActivity(intent);
};
}

protected override void OnDestroy()
{
Log.Debug(GetType().FullName, "Activity A - On Destroy");
base.OnDestroy();
}

protected override void OnPause()
{
Log.Debug(GetType().FullName, "Activity A - OnPause");
base.OnPause();
}

protected override void OnRestart()
{
Log.Debug(GetType().FullName, "Activity A - OnRestart");
base.OnRestart();
}

protected override void OnResume()
{
Log.Debug(GetType().FullName, "Activity A - OnResume");
base.OnResume();
}

protected override void OnStart()
{
Log.Debug(GetType().FullName, "Activity A - OnStart");
base.OnStart();
}

protected override void OnStop()
{
Log.Debug(GetType().FullName, "Activity A - OnStop");
base.OnStop();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="ActivityLifecycle.ActivityLifecycle" android:versionCode="1" android:versionName="1.0">
<uses-sdk android:minSdkVersion="19" />
<application android:label="ActivityLifecycle" android:icon="@drawable/Icon"></application>
</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using Android.App;

// Information about this assembly is defined by the following attributes.
// Change them to the values specific to your project.

[assembly: AssemblyTitle("ActivityLifecycle")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("")]
[assembly: AssemblyCopyright("")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
// and "{Major}.{Minor}.{Build}.*" will update just the revision.

[assembly: AssemblyVersion("1.0.0")]

// The following attributes are used to specify the signing key for the assembly,
// if desired. See the Mono documentation for more information about signing.

//[assembly: AssemblyDelaySign(false)]
//[assembly: AssemblyKeyFile("")]

Loading

0 comments on commit 41f13b5

Please sign in to comment.